[FFmpeg-devel] [PATCH v2 5/5] avformat/tee: Use BSF list API
sebechlebskyjan at gmail.com
sebechlebskyjan at gmail.com
Fri Aug 5 16:45:54 EEST 2016
From: Jan Sebechlebsky <sebechlebskyjan at gmail.com>
Signed-off-by: Jan Sebechlebsky <sebechlebskyjan at gmail.com>
---
No changes from the last version, just rebased after Michael's commit.
libavformat/tee.c | 80 +++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 57 insertions(+), 23 deletions(-)
diff --git a/libavformat/tee.c b/libavformat/tee.c
index 5689ca3..179ad2d 100644
--- a/libavformat/tee.c
+++ b/libavformat/tee.c
@@ -37,7 +37,7 @@ typedef enum {
typedef struct {
AVFormatContext *avf;
- AVBitStreamFilterContext **bsfs; ///< bitstream filters per stream
+ AVBSFContext **bsfs; ///< bitstream filters per stream
SlaveFailurePolicy on_fail;
@@ -135,14 +135,8 @@ static int close_slave(TeeSlave *tee_slave)
ret = av_write_trailer(avf);
if (tee_slave->bsfs) {
- for (i = 0; i < avf->nb_streams; ++i) {
- AVBitStreamFilterContext *bsf_next, *bsf = tee_slave->bsfs[i];
- while (bsf) {
- bsf_next = bsf->next;
- av_bitstream_filter_close(bsf);
- bsf = bsf_next;
- }
- }
+ for (i = 0; i < avf->nb_streams; ++i)
+ av_bsf_free(&tee_slave->bsfs[i]);
}
av_freep(&tee_slave->stream_map);
av_freep(&tee_slave->bsfs);
@@ -312,7 +306,7 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
"output '%s', filters will be ignored\n", i, filename);
continue;
}
- ret = parse_bsfs(avf, entry->value, &tee_slave->bsfs[i]);
+ ret = av_bsf_list_parse_str(entry->value, &tee_slave->bsfs[i]);
if (ret < 0) {
av_log(avf, AV_LOG_ERROR,
"Error parsing bitstream filter sequence '%s' associated to "
@@ -325,6 +319,31 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
av_dict_set(&options, entry->key, NULL, 0);
}
+ for (i = 0; i < avf2->nb_streams; i++){
+ if (!tee_slave->bsfs[i]) {
+ /* Add pass-through bitstream filter */
+ ret = av_bsf_get_null_filter(&tee_slave->bsfs[i]);
+ if (ret < 0) {
+ av_log(avf, AV_LOG_ERROR,
+ "Failed to create pass-through bitstream filter: %s\n",
+ av_err2str(ret));
+ goto end;
+ }
+ }
+
+ tee_slave->bsfs[i]->time_base_in = avf2->streams[i]->time_base;
+ ret = avcodec_parameters_copy(tee_slave->bsfs[i]->par_in,
+ avf2->streams[i]->codecpar);
+
+ ret = av_bsf_init(tee_slave->bsfs[i]);
+ if (ret < 0) {
+ av_log(avf, AV_LOG_ERROR,
+ "Failed to initialize bitstream filter(s): %s\n",
+ av_err2str(ret));
+ goto end;
+ }
+ }
+
if (options) {
entry = NULL;
while ((entry = av_dict_get(options, "", entry, AV_DICT_IGNORE_SUFFIX)))
@@ -349,20 +368,16 @@ static void log_slave(TeeSlave *slave, void *log_ctx, int log_level)
slave->avf->filename, slave->avf->oformat->name);
for (i = 0; i < slave->avf->nb_streams; i++) {
AVStream *st = slave->avf->streams[i];
- AVBitStreamFilterContext *bsf = slave->bsfs[i];
+ AVBSFContext *bsf = slave->bsfs[i];
+ const char * bsf_name;
av_log(log_ctx, log_level, " stream:%d codec:%s type:%s",
i, avcodec_get_name(st->codecpar->codec_id),
av_get_media_type_string(st->codecpar->codec_type));
- if (bsf) {
- av_log(log_ctx, log_level, " bsfs:");
- while (bsf) {
- av_log(log_ctx, log_level, "%s%s",
- bsf->filter->name, bsf->next ? "," : "");
- bsf = bsf->next;
- }
- }
- av_log(log_ctx, log_level, "\n");
+
+ bsf_name = bsf->filter->priv_class ?
+ bsf->filter->priv_class->item_name(bsf) : bsf->filter->name;
+ av_log(log_ctx, log_level, " bsfs: %s\n", bsf_name);
}
}
@@ -506,13 +521,32 @@ static int tee_write_packet(AVFormatContext *avf, AVPacket *pkt)
av_packet_rescale_ts(&pkt2, tb, tb2);
pkt2.stream_index = s2;
- if ((ret = av_apply_bitstream_filters(avf2->streams[s2]->codec, &pkt2,
- tee->slaves[i].bsfs[s2])) < 0 ||
- (ret = av_interleaved_write_frame(avf2, &pkt2)) < 0) {
+ ret = av_bsf_send_packet(tee->slaves[i].bsfs[s2], &pkt2);
+ if (ret < 0) {
+ av_log(avf, AV_LOG_ERROR, "Error while sending packet to bitstream filter: %s\n",
+ av_err2str(ret));
ret = tee_process_slave_failure(avf, i, ret);
if (!ret_all && ret < 0)
ret_all = ret;
}
+
+ do {
+ ret = av_bsf_receive_packet(tee->slaves[i].bsfs[s2], &pkt2);
+ if (ret < 0)
+ break;
+
+ av_packet_rescale_ts(&pkt2, tb, tb2);
+ ret = av_interleaved_write_frame(avf2, &pkt2);
+ } while (!ret);
+
+ if (ret == AVERROR(EAGAIN)) {
+ ret = 0;
+ } else if (ret < 0) {
+ ret = tee_process_slave_failure(avf, i, ret);
+ if (!ret_all && ret < 0)
+ ret_all = ret;
+ }
+
}
return ret_all;
}
--
1.9.1
More information about the ffmpeg-devel
mailing list