avformat/matroskaenc: Cosmetics

Mainly reindentation plus some reordering in MatroskaMuxContext;
moreover, use the IS_SEEKABLE() macro troughout the code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt
2020-04-29 07:24:02 +02:00
parent 575557ce66
commit 0e5ff31545

View File

@@ -128,31 +128,31 @@ typedef struct MatroskaMuxContext {
ebml_stored_master tags; ebml_stored_master tags;
int64_t segment_offset; int64_t segment_offset;
AVIOContext *cluster_bc; AVIOContext *cluster_bc;
int64_t cluster_pos; ///< file offset of the current cluster int64_t cluster_pos; ///< file offset of the current Cluster
int64_t cluster_pts; int64_t cluster_pts;
int64_t duration_offset; int64_t duration_offset;
int64_t duration; int64_t duration;
mkv_track *tracks;
mkv_seekhead seekhead; mkv_seekhead seekhead;
mkv_cues cues; mkv_cues cues;
mkv_track *tracks; int64_t cues_pos;
AVPacket cur_audio_pkt; AVPacket cur_audio_pkt;
unsigned nb_attachments; unsigned nb_attachments;
int have_video; int have_video;
int reserve_cues_space;
int cluster_size_limit;
int64_t cues_pos;
int64_t cluster_time_limit;
int is_dash;
int dash_track_number;
int is_live;
int write_crc;
uint32_t chapter_id_offset; uint32_t chapter_id_offset;
int wrote_chapters; int wrote_chapters;
int reserve_cues_space;
int cluster_size_limit;
int64_t cluster_time_limit;
int write_crc;
int is_live;
int is_dash;
int dash_track_number;
int allow_raw_vfw; int allow_raw_vfw;
int default_mode; int default_mode;
@@ -418,7 +418,7 @@ static int end_ebml_master_crc32_tentatively(AVIOContext *pb,
ebml_stored_master *elem, ebml_stored_master *elem,
MatroskaMuxContext *mkv, uint32_t id) MatroskaMuxContext *mkv, uint32_t id)
{ {
if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { if (IS_SEEKABLE(pb, mkv)) {
uint8_t *buf; uint8_t *buf;
int size = avio_get_dyn_buf(elem->bc, &buf); int size = avio_get_dyn_buf(elem->bc, &buf);
@@ -827,8 +827,8 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb,
return ret; return ret;
} }
static void mkv_write_video_color(AVIOContext *pb, const AVCodecParameters *par, static void mkv_write_video_color(AVIOContext *pb, const AVStream *st,
const AVStream *st) const AVCodecParameters *par)
{ {
/* 18 Elements with two bytes ID, one byte length field, 8 bytes payload /* 18 Elements with two bytes ID, one byte length field, 8 bytes payload
* a master element with two bytes ID and one byte length field * a master element with two bytes ID and one byte length field
@@ -911,10 +911,9 @@ static void mkv_write_video_color(AVIOContext *pb, const AVCodecParameters *par,
} }
colorinfo_size = avio_tell(dyn_cp); colorinfo_size = avio_tell(dyn_cp);
if (colorinfo_size) { if (colorinfo_size)
put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLOR, colour, colorinfo_size); put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLOR, colour, colorinfo_size);
} }
}
static int mkv_write_video_projection(AVFormatContext *s, AVIOContext *pb, static int mkv_write_video_projection(AVFormatContext *s, AVIOContext *pb,
const AVStream *st) const AVStream *st)
@@ -1306,7 +1305,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
uint32_t color_space = av_le2ne32(par->codec_tag); uint32_t color_space = av_le2ne32(par->codec_tag);
put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space)); put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space));
} }
mkv_write_video_color(pb, par, st); mkv_write_video_color(pb, st, par);
ret = mkv_write_video_projection(s, pb, st); ret = mkv_write_video_projection(s, pb, st);
if (ret < 0) if (ret < 0)
@@ -1616,7 +1615,7 @@ static int mkv_check_tag(const AVDictionary *m, uint32_t elementid)
static int mkv_write_tags(AVFormatContext *s) static int mkv_write_tags(AVFormatContext *s)
{ {
MatroskaMuxContext *mkv = s->priv_data; MatroskaMuxContext *mkv = s->priv_data;
ebml_master tag, *tagp; ebml_master tag, *tagp = IS_SEEKABLE(s->pb, mkv) ? &tag : NULL;
int i, ret; int i, ret;
ff_metadata_conv_ctx(s, ff_mkv_metadata_conv, NULL); ff_metadata_conv_ctx(s, ff_mkv_metadata_conv, NULL);
@@ -1627,7 +1626,6 @@ static int mkv_write_tags(AVFormatContext *s)
return ret; return ret;
} }
tagp = (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live ? &tag : NULL;
for (i = 0; i < s->nb_streams; i++) { for (i = 0; i < s->nb_streams; i++) {
const AVStream *st = s->streams[i]; const AVStream *st = s->streams[i];
mkv_track *track = &mkv->tracks[i]; mkv_track *track = &mkv->tracks[i];
@@ -1820,7 +1818,7 @@ static int mkv_write_header(AVFormatContext *s)
put_ebml_size_unknown(pb, 8); put_ebml_size_unknown(pb, 8);
mkv->segment_offset = avio_tell(pb); mkv->segment_offset = avio_tell(pb);
// we write a seek head at the beginning to point to all other level // We write a SeekHead at the beginning to point to all other level
// one elements (except Clusters). // one elements (except Clusters).
mkv_start_seekhead(mkv, pb); mkv_start_seekhead(mkv, pb);
@@ -1898,7 +1896,7 @@ static int mkv_write_header(AVFormatContext *s)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) || mkv->is_live) { if (!IS_SEEKABLE(pb, mkv)) {
ret = mkv_write_seekhead(pb, mkv, 0, avio_tell(pb)); ret = mkv_write_seekhead(pb, mkv, 0, avio_tell(pb));
if (ret < 0) if (ret < 0)
return ret; return ret;
@@ -2512,7 +2510,6 @@ static int mkv_write_trailer(AVFormatContext *s)
"%d < %"PRIu64". No Cues will be output.\n", "%d < %"PRIu64". No Cues will be output.\n",
mkv->reserve_cues_space, size); mkv->reserve_cues_space, size);
ret2 = AVERROR(EINVAL); ret2 = AVERROR(EINVAL);
ffio_free_dyn_buf(&cues);
goto after_cues; goto after_cues;
} else { } else {
if ((ret64 = avio_seek(pb, mkv->cues_pos, SEEK_SET)) < 0) { if ((ret64 = avio_seek(pb, mkv->cues_pos, SEEK_SET)) < 0) {