| 1174 | } |
| 1175 | |
| 1176 | int av_write_frame(AVFormatContext *s, AVPacket *in) |
| 1177 | { |
| 1178 | FFFormatContext *const si = ffformatcontext(s); |
| 1179 | AVPacket *pkt = si->parse_pkt; |
| 1180 | int ret; |
| 1181 | |
| 1182 | if (!in) { |
| 1183 | if (ffofmt(s->oformat)->flags_internal & FF_OFMT_FLAG_ALLOW_FLUSH) { |
| 1184 | ret = ffofmt(s->oformat)->write_packet(s, NULL); |
| 1185 | flush_if_needed(s); |
| 1186 | if (ret >= 0 && s->pb && s->pb->error < 0) |
| 1187 | ret = s->pb->error; |
| 1188 | return ret; |
| 1189 | } |
| 1190 | return 1; |
| 1191 | } |
| 1192 | |
| 1193 | if (in->flags & AV_PKT_FLAG_UNCODED_FRAME) { |
| 1194 | pkt = in; |
| 1195 | } else { |
| 1196 | /* We don't own in, so we have to make sure not to modify it. |
| 1197 | * (ff_write_chained() relies on this fact.) |
| 1198 | * The following avoids copying in's data unnecessarily. |
| 1199 | * Copying side data is unavoidable as a bitstream filter |
| 1200 | * may change it, e.g. free it on errors. */ |
| 1201 | pkt->data = in->data; |
| 1202 | pkt->size = in->size; |
| 1203 | ret = av_packet_copy_props(pkt, in); |
| 1204 | if (ret < 0) |
| 1205 | return ret; |
| 1206 | if (in->buf) { |
| 1207 | pkt->buf = av_buffer_ref(in->buf); |
| 1208 | if (!pkt->buf) { |
| 1209 | ret = AVERROR(ENOMEM); |
| 1210 | goto fail; |
| 1211 | } |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | ret = write_packets_common(s, pkt, 0/*non-interleaved*/); |
| 1216 | |
| 1217 | fail: |
| 1218 | // Uncoded frames using the noninterleaved codepath are also freed here |
| 1219 | av_packet_unref(pkt); |
| 1220 | return ret; |
| 1221 | } |
| 1222 | |
| 1223 | int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) |
| 1224 | { |