count++;
}
- if (!(fmts = av_malloc((count+1) * sizeof(int))))
+ if (!(fmts = av_malloc_array(count + 1, sizeof(*fmts))))
return NULL;
for (j = 0, i = 0; i < n; i++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
if (lavfi->dump_graph) {
char *dump = avfilter_graph_dump(lavfi->graph, lavfi->dump_graph);
- fputs(dump, stderr);
- fflush(stderr);
- av_free(dump);
+ if (dump != NULL) {
+ fputs(dump, stderr);
+ fflush(stderr);
+ av_free(dump);
+ } else {
+ FAIL(AVERROR(ENOMEM));
+ }
}
/* fill each stream with the information in the corresponding sink */
{
LavfiContext *lavfi = avctx->priv_data;
AVFrameSideData *sd;
- int stream_idx, i, ret;
+ int stream_idx, ret;
if ((stream_idx = lavfi->sink_stream_subcc_map[sink_idx]) < 0)
return 0;
- for (i = 0; i < frame->nb_side_data; i++)
- if (frame->side_data[i]->type == AV_FRAME_DATA_A53_CC)
- break;
- if (i >= frame->nb_side_data)
+ if (!(sd = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC)))
return 0;
- sd = frame->side_data[i];
if ((ret = av_new_packet(&lavfi->subcc_packet, sd->size)) < 0)
return ret;
memcpy(lavfi->subcc_packet.data, sd->data, sd->size);
AVDictionary *frame_metadata;
int ret, i;
int size = 0;
+ AVStream *st;
if (lavfi->subcc_packet.size) {
- *pkt = lavfi->subcc_packet;
- av_init_packet(&lavfi->subcc_packet);
- lavfi->subcc_packet.size = 0;
- lavfi->subcc_packet.data = NULL;
+ av_packet_move_ref(pkt, &lavfi->subcc_packet);
return pkt->size;
}
av_buffersink_get_frame_flags(lavfi->sinks[min_pts_sink_idx], frame, 0);
stream_idx = lavfi->sink_stream_map[min_pts_sink_idx];
+ st = avctx->streams[stream_idx];
- if (frame->width /* FIXME best way of testing a video */) {
+ if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
size = av_image_get_buffer_size(frame->format, frame->width, frame->height, 1);
if ((ret = av_new_packet(pkt, size)) < 0)
- return ret;
+ goto fail;
av_image_copy_to_buffer(pkt->data, size, (const uint8_t **)frame->data, frame->linesize,
frame->format, frame->width, frame->height, 1);
- } else if (frame->channels /* FIXME test audio */) {
+ } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
size = frame->nb_samples * av_get_bytes_per_sample(frame->format) *
frame->channels;
if ((ret = av_new_packet(pkt, size)) < 0)
- return ret;
+ goto fail;
memcpy(pkt->data, frame->data[0], size);
}
frame_metadata = frame->metadata;
if (frame_metadata) {
- uint8_t *metadata;
- AVDictionaryEntry *e = NULL;
- AVBPrint meta_buf;
-
- av_bprint_init(&meta_buf, 0, AV_BPRINT_SIZE_UNLIMITED);
- while ((e = av_dict_get(frame_metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {
- av_bprintf(&meta_buf, "%s", e->key);
- av_bprint_chars(&meta_buf, '\0', 1);
- av_bprintf(&meta_buf, "%s", e->value);
- av_bprint_chars(&meta_buf, '\0', 1);
+ size_t size;
+ uint8_t *metadata = av_packet_pack_dictionary(frame_metadata, &size);
+
+ if (!metadata) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
}
- if (!av_bprint_is_complete(&meta_buf) ||
- !(metadata = av_packet_new_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA,
- meta_buf.len))) {
- av_bprint_finalize(&meta_buf, NULL);
- return AVERROR(ENOMEM);
+ if ((ret = av_packet_add_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA,
+ metadata, size)) < 0) {
+ av_freep(&metadata);
+ goto fail;
}
- memcpy(metadata, meta_buf.str, meta_buf.len);
- av_bprint_finalize(&meta_buf, NULL);
}
if ((ret = create_subcc_packet(avctx, frame, min_pts_sink_idx)) < 0) {
- av_frame_unref(frame);
- av_packet_unref(pkt);
- return ret;
+ goto fail;
}
pkt->stream_index = stream_idx;
pkt->pts = frame->pts;
pkt->pos = frame->pkt_pos;
- pkt->size = size;
av_frame_unref(frame);
return size;
+fail:
+ av_frame_unref(frame);
+ return ret;
+
}
#define OFFSET(x) offsetof(LavfiContext, x)
.category = AV_CLASS_CATEGORY_DEVICE_INPUT,
};
-AVInputFormat ff_lavfi_demuxer = {
+const AVInputFormat ff_lavfi_demuxer = {
.name = "lavfi",
.long_name = NULL_IF_CONFIG_SMALL("Libavfilter virtual input device"),
.priv_data_size = sizeof(LavfiContext),