From 74cafb0e6f3c5ec9d68b6e75e4257d77c3055805 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Tue, 15 Oct 2019 13:17:34 +0200 Subject: [PATCH] avformat/matroskaenc: Cosmetics Contains renaming of variables (e.g. mkv_write_cues() contained variables called tracknum that actually contain the index of a track in s->streams and not the track number (which can differ in case an explicit dash track number is set)). Signed-off-by: Andreas Rheinhardt Signed-off-by: James Almer --- libavformat/matroskaenc.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 6551734427385..ba48aae454235 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -80,7 +80,7 @@ typedef struct mkv_cuepoint { uint64_t pts; int stream_idx; int tracknum; - int64_t cluster_pos; ///< file offset of the cluster containing the block + int64_t cluster_pos; ///< offset of the cluster containing the block relative to the segment int64_t relative_pos; ///< relative offset from the position of the cluster containing the block int64_t duration; ///< duration of the block according to time base } mkv_cuepoint; @@ -575,11 +575,12 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra for (j = 0; j < num_tracks; j++) tracks[j].has_cue = 0; for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) { - int tracknum = entry[j].stream_idx; - av_assert0(tracknum>=0 && tracknumstreams[tracknum]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) + int idx = entry[j].stream_idx; + + av_assert0(idx >= 0 && idx < num_tracks); + if (tracks[idx].has_cue && s->streams[idx]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) continue; - tracks[tracknum].has_cue = 1; + tracks[idx].has_cue = 1; ctp_nb ++; } @@ -591,11 +592,11 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra for (j = 0; j < num_tracks; j++) tracks[j].has_cue = 0; for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) { - int tracknum = entry[j].stream_idx; + int idx = entry[j].stream_idx; - if (tracks[tracknum].has_cue && s->streams[tracknum]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) + if (tracks[idx].has_cue && s->streams[idx]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) continue; - tracks[tracknum].has_cue = 1; + tracks[idx].has_cue = 1; track_positions = start_ebml_master(dyn_cp, MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE); put_ebml_uint(dyn_cp, MATROSKA_ID_CUETRACK , entry[j].tracknum ); put_ebml_uint(dyn_cp, MATROSKA_ID_CUECLUSTERPOSITION , entry[j].cluster_pos); @@ -2088,13 +2089,13 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, mkv_track *track = &mkv->tracks[pkt->stream_index]; uint8_t *data = NULL, *side_data = NULL; int offset = 0, size = pkt->size, side_data_size = 0; - int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts; + int64_t ts = track->write_dts ? pkt->dts : pkt->pts; uint64_t additional_id = 0; int64_t discard_padding = 0; uint8_t track_number = (mkv->is_dash ? mkv->dash_track_number : (pkt->stream_index + 1)); ebml_master block_group, block_additions, block_more; - ts += mkv->tracks[pkt->stream_index].ts_offset; + ts += track->ts_offset; /* The following string is identical to the one in mkv_write_vtt_blocks * so that only one copy needs to exist in binaries. */ @@ -2350,21 +2351,21 @@ static int mkv_check_new_extra_data(AVFormatContext *s, AVPacket *pkt) static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_cue) { MatroskaMuxContext *mkv = s->priv_data; - AVIOContext *pb = s->pb; + AVIOContext *pb; AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; mkv_track *track = &mkv->tracks[pkt->stream_index]; int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY); int duration = pkt->duration; int ret; - int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts; + int64_t ts = track->write_dts ? pkt->dts : pkt->pts; int64_t relative_packet_pos; - int dash_tracknum = mkv->is_dash ? mkv->dash_track_number : pkt->stream_index + 1; + int tracknum = mkv->is_dash ? mkv->dash_track_number : pkt->stream_index + 1; if (ts == AV_NOPTS_VALUE) { av_log(s, AV_LOG_ERROR, "Can't write packet with unknown timestamp\n"); return AVERROR(EINVAL); } - ts += mkv->tracks[pkt->stream_index].ts_offset; + ts += track->ts_offset; if (mkv->cluster_pos != -1) { int64_t cluster_time = ts - mkv->cluster_pts; @@ -2393,7 +2394,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_ if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) { mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe); if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && (par->codec_type == AVMEDIA_TYPE_VIDEO && keyframe || add_cue)) { - ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, dash_tracknum, ts, mkv->cluster_pos, relative_packet_pos, -1); + ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, tracknum, ts, mkv->cluster_pos, relative_packet_pos, -1); if (ret < 0) return ret; } } else { @@ -2418,15 +2419,14 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) { - ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, dash_tracknum, ts, + ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, tracknum, ts, mkv->cluster_pos, relative_packet_pos, duration); if (ret < 0) return ret; } } - mkv->duration = FFMAX(mkv->duration, ts + duration); - + mkv->duration = FFMAX(mkv->duration, ts + duration); track->duration = FFMAX(track->duration, ts + duration); return 0;