[FFmpeg-cvslog] avfilter/vf_v360: fix swapped variables
ffmpeg | branch: master | Paul B Mahol | Sun Mar 29 13:18:25 2020 +0200| [72be5d4661685ecaca372eae78b50e1583e4dab9] | committer: Paul B Mahol avfilter/vf_v360: fix swapped variables > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=72be5d4661685ecaca372eae78b50e1583e4dab9 --- libavfilter/vf_v360.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c index 75f512e242..54d4d23825 100644 --- a/libavfilter/vf_v360.c +++ b/libavfilter/vf_v360.c @@ -3565,8 +3565,8 @@ static void fov_from_dfov(int format, float d_fov, float w, float h, float *h_fo { const float d = 0.5f * hypotf(w, h); -*h_fov = d / h * d_fov; -*v_fov = d / w * d_fov; +*h_fov = d / w * d_fov; +*v_fov = d / h * d_fov; } break; case FLAT: ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avfilter/vf_v360: reduce unnecessary negations
ffmpeg | branch: master | Paul B Mahol | Sat Mar 28 22:51:25 2020 +0100| [460001981fff7fd9ceff9e432dad121af0f0d2c3] | committer: Paul B Mahol avfilter/vf_v360: reduce unnecessary negations > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=460001981fff7fd9ceff9e432dad121af0f0d2c3 --- libavfilter/vf_v360.c | 306 +- 1 file changed, 153 insertions(+), 153 deletions(-) diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c index b3443f2001..66e3f09f6d 100644 --- a/libavfilter/vf_v360.c +++ b/libavfilter/vf_v360.c @@ -942,33 +942,33 @@ static void cube_to_xyz(const V360Context *s, switch (direction) { case RIGHT: l_x = 1.f; -l_y = -vf; -l_z = uf; +l_y = vf; +l_z = -uf; break; case LEFT: l_x = -1.f; -l_y = -vf; -l_z = -uf; +l_y = vf; +l_z = uf; break; case UP: l_x = uf; -l_y = 1.f; -l_z = -vf; +l_y = -1.f; +l_z = vf; break; case DOWN: l_x = uf; -l_y = -1.f; -l_z = vf; +l_y = 1.f; +l_z = -vf; break; case FRONT: l_x = uf; -l_y = -vf; -l_z = -1.f; +l_y = vf; +l_z = 1.f; break; case BACK: l_x = -uf; -l_y = -vf; -l_z = 1.f; +l_y = vf; +l_z = -1.f; break; default: av_assert0(0); @@ -995,8 +995,8 @@ static void xyz_to_cube(const V360Context *s, const float *vec, float *uf, float *vf, int *direction) { -const float phi = atan2f(vec[0], -vec[2]); -const float theta = asinf(-vec[1]); +const float phi = atan2f(vec[0], vec[2]); +const float theta = asinf(vec[1]); float phi_norm, theta_threshold; int face; @@ -1023,27 +1023,27 @@ static void xyz_to_cube(const V360Context *s, switch (*direction) { case RIGHT: -*uf = vec[2] / vec[0]; -*vf = -vec[1] / vec[0]; +*uf = -vec[2] / vec[0]; +*vf = vec[1] / vec[0]; break; case LEFT: -*uf = vec[2] / vec[0]; -*vf = vec[1] / vec[0]; +*uf = -vec[2] / vec[0]; +*vf = -vec[1] / vec[0]; break; case UP: -*uf = vec[0] / vec[1]; +*uf = -vec[0] / vec[1]; *vf = -vec[2] / vec[1]; break; case DOWN: -*uf = -vec[0] / vec[1]; +*uf = vec[0] / vec[1]; *vf = -vec[2] / vec[1]; break; case FRONT: -*uf = -vec[0] / vec[2]; +*uf = vec[0] / vec[2]; *vf = vec[1] / vec[2]; break; case BACK: -*uf = -vec[0] / vec[2]; +*uf = vec[0] / vec[2]; *vf = -vec[1] / vec[2]; break; default: @@ -1627,9 +1627,9 @@ static int equirect_to_xyz(const V360Context *s, const float sin_theta = sinf(theta); const float cos_theta = cosf(theta); -vec[0] = cos_theta * sin_phi; -vec[1] = -sin_theta; -vec[2] = -cos_theta * cos_phi; +vec[0] = cos_theta * sin_phi; +vec[1] = sin_theta; +vec[2] = cos_theta * cos_phi; return 1; } @@ -1656,9 +1656,9 @@ static int hequirect_to_xyz(const V360Context *s, const float sin_theta = sinf(theta); const float cos_theta = cosf(theta); -vec[0] = cos_theta * sin_phi; -vec[1] = -sin_theta; -vec[2] = -cos_theta * cos_phi; +vec[0] = cos_theta * sin_phi; +vec[1] = sin_theta; +vec[2] = cos_theta * cos_phi; return 1; } @@ -1700,9 +1700,9 @@ static int stereographic_to_xyz(const V360Context *s, const float theta = atanf(r) * 2.f; const float sin_theta = sinf(theta); -vec[0] = x / r * sin_theta; -vec[1] = -y / r * sin_theta; -vec[2] = -cosf(theta); +vec[0] = x / r * sin_theta; +vec[1] = y / r * sin_theta; +vec[2] = cosf(theta); normalize_vector(vec); @@ -1742,11 +1742,11 @@ static int xyz_to_stereographic(const V360Context *s, const float *vec, int width, int height, int16_t us[4][4], int16_t vs[4][4], float *du, float *dv) { -const float theta = acosf(-vec[2]); +const float theta = acosf(vec[2]); const float r = tanf(theta * 0.5f); const float c = r / hypotf(vec[0], vec[1]); -const float x = vec[0] * c / s->iflat_range[0] * s->input_mirror_modifier[0]; -const float y = -vec[1] * c / s->iflat_range[1] * s->input_mirror_modifier[1]; +const float x = vec[0] * c / s->iflat_range[0] * s->input_mirror_modifier[0]; +const float y = vec[1] * c / s->iflat_range[1] * s->input_mirror_modifier[1]; const float uf = (x + 1.f) * width / 2.f; const float vf = (y + 1.f) * height / 2.f; @@ -1785,8 +1785,8 @@ static int xyz_to_equirect(const V360Context *s, const float *vec, int width, i
[FFmpeg-cvslog] avfilter/vf_v360: speedup fisheye output
ffmpeg | branch: master | Paul B Mahol | Sun Mar 29 13:07:35 2020 +0200| [85025162dac9efcb07ed7528cbd248337bad912c] | committer: Paul B Mahol avfilter/vf_v360: speedup fisheye output > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=85025162dac9efcb07ed7528cbd248337bad912c --- libavfilter/vf_v360.c | 11 --- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c index 66e3f09f6d..75f512e242 100644 --- a/libavfilter/vf_v360.c +++ b/libavfilter/vf_v360.c @@ -2531,9 +2531,14 @@ static int fisheye_to_xyz(const V360Context *s, const float phi = atan2f(vf, uf); const float theta = M_PI_2 * (1.f - hypotf(uf, vf)); -vec[0] = cosf(theta) * cosf(phi); -vec[1] = cosf(theta) * sinf(phi); -vec[2] = sinf(theta); +const float sin_phi = sinf(phi); +const float cos_phi = cosf(phi); +const float sin_theta = sinf(theta); +const float cos_theta = cosf(theta); + +vec[0] = cos_theta * cos_phi; +vec[1] = cos_theta * sin_phi; +vec[2] = sin_theta; normalize_vector(vec); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/matroskaenc: Improve calculating EBML ID size
ffmpeg | branch: master | Andreas Rheinhardt | Sat Dec 28 10:00:37 2019 +0100| [e6ea75a38de192c3133b9eebe603979bffeed20b] | committer: Andreas Rheinhardt avformat/matroskaenc: Improve calculating EBML ID size When the Matroska muxer writes an EBML ID, it calculates the length of said ID before; and it does this as if this were a number that needs to be encoded as EBML number: The formula used is (av_log2(id + 1) - 1) / 7 + 1. But the constants used already contain the VINT_MARKER (the leading bit indicating the length of the EBML number) and therefore the algorithm used makes no sense. Instead the position of the most significant byte set gives the desired length. The algorithm used until now worked because EBML numbers are subject to restrictions: If the EBML number takes up k bytes, then the bit 1 << (7 * k) is set and av_log2(id) is 7 * k. So the current algorithm produces the correct result unless the EBML ID is of the form 7 * k - 1 because of the "id + 1". But contrary to encoding lengths as EBML number (where the + 1 exists to avoid the encodings reserved for unknown length), such EBML numbers are simply forbidden as EBML IDs and as such none of them were ever written. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e6ea75a38de192c3133b9eebe603979bffeed20b --- libavformat/matroskaenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index f9e69c6c89..c484d95c2f 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -183,7 +183,7 @@ typedef struct MatroskaMuxContext { static int ebml_id_size(uint32_t id) { -return (av_log2(id + 1) - 1) / 7 + 1; +return (av_log2(id) + 7U) / 8; } static void put_ebml_id(AVIOContext *pb, uint32_t id) ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/matroskaenc: Check for failure when writing SeekHead
ffmpeg | branch: master | Andreas Rheinhardt | Sun Dec 29 09:57:44 2019 +0100| [8c89fc18e6125ae0449091d82a2fe200ed848c43] | committer: Andreas Rheinhardt avformat/matroskaenc: Check for failure when writing SeekHead mkv_write_seekhead() would up until now try to seek to the position where the SeekHead ought to be written, write the SeekHead and seek back. The first of these seeks was checked as was writing, yet the seek back was unchecked. Moreover the return value of mkv_write_seekhead() was unchecked (the ordinary return value was the position where the SeekHead was written). This commit changes this: Everything is checked. In the unseekable case (where the first seek may nevertheless work when it happens in the buffer) a failure at the first seek is not considered an error. In any case, failure to seek back is an error. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8c89fc18e6125ae0449091d82a2fe200ed848c43 --- libavformat/matroskaenc.c | 48 +-- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index c484d95c2f..8eb968445d 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -436,30 +436,31 @@ static void mkv_add_seekhead_entry(MatroskaMuxContext *mkv, uint32_t elementid, } /** - * Write the SeekHead to the file at the location reserved for it. + * Write the SeekHead to the file at the location reserved for it + * and seek back to the initial position. When error_on_seek_failure + * is not set, failure to seek to the position designated for the + * SeekHead is not considered an error; failure to seek back afterwards + * is always an error. * - * @return The file offset where the seekhead was written, - * -1 if an error occurred. + * @return 0 on success, < 0 on error. */ -static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv) +static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, + int error_on_seek_failure) { AVIOContext *dyn_cp; mkv_seekhead *seekhead = &mkv->seekhead; ebml_master seekentry; -int64_t currentpos, remaining; -int i; +int64_t currentpos, remaining, ret64; +int i, ret; currentpos = avio_tell(pb); -if (avio_seek(pb, seekhead->filepos, SEEK_SET) < 0) { -currentpos = -1; -goto fail; -} +if ((ret64 = avio_seek(pb, seekhead->filepos, SEEK_SET)) < 0) +return error_on_seek_failure ? ret64 : 0; -if (start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD) < 0) { -currentpos = -1; -goto fail; -} +ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD); +if (ret < 0) +return ret; for (i = 0; i < seekhead->num_entries; i++) { mkv_seekhead_entry *entry = &seekhead->entries[i]; @@ -477,13 +478,11 @@ static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv) remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb); put_ebml_void(pb, remaining); -avio_seek(pb, currentpos, SEEK_SET); -currentpos = seekhead->filepos; +if ((ret64 = avio_seek(pb, currentpos, SEEK_SET)) < 0) +return ret64; -fail: - -return currentpos; +return 0; } static mkv_cues *mkv_start_cues(int64_t segment_offset) @@ -1927,8 +1926,11 @@ static int mkv_write_header(AVFormatContext *s) if (ret < 0) return ret; -if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) -mkv_write_seekhead(pb, mkv); +if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { +ret = mkv_write_seekhead(pb, mkv, 0); +if (ret < 0) +return ret; +} mkv->cues = mkv_start_cues(mkv->segment_offset); if (!mkv->cues) { @@ -2537,7 +2539,9 @@ static int mkv_write_trailer(AVFormatContext *s) mkv_add_seekhead_entry(mkv, MATROSKA_ID_CUES, cuespos); } -mkv_write_seekhead(pb, mkv); +ret = mkv_write_seekhead(pb, mkv, 1); +if (ret < 0) +return ret; // update the duration av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\n", mkv->duration); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/matroskaenc: Avoid unnecessary seek
ffmpeg | branch: master | Andreas Rheinhardt | Sun Dec 29 12:50:46 2019 +0100| [b1c3d711df0d50bc367cc7000f346ae700667a31] | committer: Andreas Rheinhardt avformat/matroskaenc: Avoid unnecessary seek When writing the SeekHead (a form of index) at the end of the muxing process, mkv_write_seekhead() would first seek to the position where the SeekHead ought to be written, then write it there and seek back to the original position afterwards. Which means: To the end of the file. Afterwards, a seek to the beginning of the file is performed to update further values. This of course means that the second seek in mkv_write_seekhead() was unnecessary. This has been changed: A new parameter was added to mkv_write_seekhead() containing the destination for the second seek, effectively eliminating the seek to the end of the file after writing the SeekHead. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b1c3d711df0d50bc367cc7000f346ae700667a31 --- libavformat/matroskaenc.c | 23 +++ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 8eb968445d..582ea52f23 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -437,24 +437,23 @@ static void mkv_add_seekhead_entry(MatroskaMuxContext *mkv, uint32_t elementid, /** * Write the SeekHead to the file at the location reserved for it - * and seek back to the initial position. When error_on_seek_failure + * and seek to destpos afterwards. When error_on_seek_failure * is not set, failure to seek to the position designated for the - * SeekHead is not considered an error; failure to seek back afterwards - * is always an error. + * SeekHead is not considered an error and it is presumed that + * destpos is the current position; failure to seek to destpos + * afterwards is always an error. * * @return 0 on success, < 0 on error. */ static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, - int error_on_seek_failure) + int error_on_seek_failure, int64_t destpos) { AVIOContext *dyn_cp; mkv_seekhead *seekhead = &mkv->seekhead; ebml_master seekentry; -int64_t currentpos, remaining, ret64; +int64_t remaining, ret64; int i, ret; -currentpos = avio_tell(pb); - if ((ret64 = avio_seek(pb, seekhead->filepos, SEEK_SET)) < 0) return error_on_seek_failure ? ret64 : 0; @@ -479,7 +478,7 @@ static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb); put_ebml_void(pb, remaining); -if ((ret64 = avio_seek(pb, currentpos, SEEK_SET)) < 0) +if ((ret64 = avio_seek(pb, destpos, SEEK_SET)) < 0) return ret64; return 0; @@ -1927,7 +1926,7 @@ static int mkv_write_header(AVFormatContext *s) return ret; if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { -ret = mkv_write_seekhead(pb, mkv, 0); +ret = mkv_write_seekhead(pb, mkv, 0, avio_tell(pb)); if (ret < 0) return ret; } @@ -2539,16 +2538,16 @@ static int mkv_write_trailer(AVFormatContext *s) mkv_add_seekhead_entry(mkv, MATROSKA_ID_CUES, cuespos); } -ret = mkv_write_seekhead(pb, mkv, 1); +currentpos = avio_tell(pb); + +ret = mkv_write_seekhead(pb, mkv, 1, mkv->info_pos); if (ret < 0) return ret; // update the duration av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\n", mkv->duration); -currentpos = avio_tell(pb); avio_seek(mkv->info_bc, mkv->duration_offset, SEEK_SET); put_ebml_float(mkv->info_bc, MATROSKA_ID_DURATION, mkv->duration); -avio_seek(pb, mkv->info_pos, SEEK_SET); end_ebml_master_crc32(pb, &mkv->info_bc, mkv); // write tracks master ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/matroskaenc: Cosmetics
ffmpeg | branch: master | Andreas Rheinhardt | Tue Dec 31 13:21:31 2019 +0100| [6cf69f0e72d6429ed54db0a21f165da7b06ca7e4] | committer: Andreas Rheinhardt avformat/matroskaenc: Cosmetics Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6cf69f0e72d6429ed54db0a21f165da7b06ca7e4 --- libavformat/matroskaenc.c | 7 +++ 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 582ea52f23..f76f3524d8 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -450,7 +450,6 @@ static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, { AVIOContext *dyn_cp; mkv_seekhead *seekhead = &mkv->seekhead; -ebml_master seekentry; int64_t remaining, ret64; int i, ret; @@ -463,8 +462,8 @@ static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, for (i = 0; i < seekhead->num_entries; i++) { mkv_seekhead_entry *entry = &seekhead->entries[i]; - -seekentry = start_ebml_master(dyn_cp, MATROSKA_ID_SEEKENTRY, MAX_SEEKENTRY_SIZE); +ebml_master seekentry = start_ebml_master(dyn_cp, MATROSKA_ID_SEEKENTRY, + MAX_SEEKENTRY_SIZE); put_ebml_id(dyn_cp, MATROSKA_ID_SEEKID); put_ebml_num(dyn_cp, ebml_id_size(entry->elementid), 0); @@ -476,7 +475,7 @@ static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, end_ebml_master_crc32(pb, &dyn_cp, mkv); remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb); -put_ebml_void(pb, remaining); +put_ebml_void(pb, remaining); if ((ret64 = avio_seek(pb, destpos, SEEK_SET)) < 0) return ret64; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/matroskaenc: Avoid allocation for Cues
ffmpeg | branch: master | Andreas Rheinhardt | Mon Dec 30 15:37:15 2019 +0100| [5cdd2ebb55f760d06d35b71a421b8433851b92e9] | committer: Andreas Rheinhardt avformat/matroskaenc: Avoid allocation for Cues Up until now, the Matroska muxer would allocate a structure containing three members: The segment offset, a pointer to an array containing Cue (index) entries and a counter for said array. It is unnecessary to allocate it separately and it is unnecessary to contain the segment offset in said structure, as it duplicates another field contained in the MatroskaMuxContext. This commit implements the corresponding changes. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5cdd2ebb55f760d06d35b71a421b8433851b92e9 --- libavformat/matroskaenc.c | 39 +++ 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index f76f3524d8..433a2b5579 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -88,7 +88,6 @@ typedef struct mkv_cuepoint { } mkv_cuepoint; typedef struct mkv_cues { -int64_t segment_offset; mkv_cuepoint*entries; int num_entries; } mkv_cues; @@ -139,7 +138,7 @@ typedef struct MatroskaMuxContext { int64_t duration_offset; int64_t duration; mkv_seekheadseekhead; -mkv_cues*cues; +mkv_cuescues; mkv_track *tracks; mkv_attachments *attachments; @@ -398,10 +397,7 @@ static void mkv_deinit(AVFormatContext *s) ffio_free_dyn_buf(&mkv->tracks_bc); ffio_free_dyn_buf(&mkv->tags_bc); -if (mkv->cues) { -av_freep(&mkv->cues->entries); -av_freep(&mkv->cues); -} +av_freep(&mkv->cues.entries); if (mkv->attachments) { av_freep(&mkv->attachments->entries); av_freep(&mkv->attachments); @@ -483,19 +479,10 @@ static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, return 0; } -static mkv_cues *mkv_start_cues(int64_t segment_offset) -{ -mkv_cues *cues = av_mallocz(sizeof(mkv_cues)); -if (!cues) -return NULL; - -cues->segment_offset = segment_offset; -return cues; -} - -static int mkv_add_cuepoint(mkv_cues *cues, int stream, int tracknum, int64_t ts, +static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int tracknum, int64_t ts, int64_t cluster_pos, int64_t relative_pos, int64_t duration) { +mkv_cues *cues = &mkv->cues; mkv_cuepoint *entries = cues->entries; if (ts < 0) @@ -509,7 +496,7 @@ static int mkv_add_cuepoint(mkv_cues *cues, int stream, int tracknum, int64_t ts cues->entries[cues->num_entries].pts = ts; cues->entries[cues->num_entries].stream_idx= stream; cues->entries[cues->num_entries].tracknum = tracknum; -cues->entries[cues->num_entries].cluster_pos = cluster_pos - cues->segment_offset; +cues->entries[cues->num_entries].cluster_pos = cluster_pos - mkv->segment_offset; cues->entries[cues->num_entries].relative_pos = relative_pos; cues->entries[cues->num_entries++].duration= duration; @@ -1930,11 +1917,6 @@ static int mkv_write_header(AVFormatContext *s) return ret; } -mkv->cues = mkv_start_cues(mkv->segment_offset); -if (!mkv->cues) { -return AVERROR(ENOMEM); -} - if (s->metadata_header_padding > 0) { if (s->metadata_header_padding == 1) s->metadata_header_padding++; @@ -2353,7 +2335,8 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_ if (ret < 0) return ret; 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, tracknum, ts, mkv->cluster_pos, relative_packet_pos, -1); +ret = mkv_add_cuepoint(mkv, pkt->stream_index, tracknum, ts, + mkv->cluster_pos, relative_packet_pos, -1); if (ret < 0) return ret; } } else { @@ -2378,7 +2361,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) { -ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, tracknum, ts, +ret = mkv_add_cuepoint(mkv, pkt->stream_index, tracknum, ts, mkv->cluster_pos, relative_packet_pos, duration); if (ret < 0) return ret; @@ -2508,14 +2491,14 @@ static int mkv_write_trailer(AVFormatContext *s) if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) { -if (mkv->cues->num_entries) { +if (mkv->cues.num_entries) { if (mkv->reserve_cues_space) { int64_t cues_end; currentpos = avio_tell(pb);
[FFmpeg-cvslog] avformat/aviobuf: Add function to reset dynamic buffer
ffmpeg | branch: master | Andreas Rheinhardt | Tue Nov 26 07:53:52 2019 +0100| [639728f51a9fa5e321effad5909c1e37df0e80bb] | committer: Andreas Rheinhardt avformat/aviobuf: Add function to reset dynamic buffer Resetting a dynamic buffer means to keep the AVIOContext and the internal buffer used by the dynamic buffer. This is done in order to save (re)allocations when one has a workflow where one opens and closes dynamic buffers in sequence. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=639728f51a9fa5e321effad5909c1e37df0e80bb --- libavformat/avio_internal.h | 7 +++ libavformat/aviobuf.c | 11 +++ 2 files changed, 18 insertions(+) diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h index eb628ac493..c575df8035 100644 --- a/libavformat/avio_internal.h +++ b/libavformat/avio_internal.h @@ -171,6 +171,13 @@ int ffio_open_whitelist(AVIOContext **s, const char *url, int flags, */ int ffio_close_null_buf(AVIOContext *s); +/** + * Reset a dynamic buffer. + * + * Resets everything, but keeps the allocated buffer for later use. + */ +void ffio_reset_dyn_buf(AVIOContext *s); + /** * Free a dynamic buffer. * diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index c4f168e49b..85c01c938a 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -1407,6 +1407,17 @@ int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer) return d->size; } +void ffio_reset_dyn_buf(AVIOContext *s) +{ +DynBuffer *d = s->opaque; +int max_packet_size = s->max_packet_size; + +ffio_init_context(s, d->io_buffer, d->io_buffer_size, 1, d, NULL, + s->write_packet, s->seek); +s->max_packet_size = max_packet_size; +d->pos = d->size = 0; +} + int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer) { DynBuffer *d; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/matroskaenc: Simplify writing Cues
ffmpeg | branch: master | Andreas Rheinhardt | Mon Dec 30 15:48:35 2019 +0100| [5e3b7bd56d2c476a508c03e2029675bfd2618122] | committer: Andreas Rheinhardt avformat/matroskaenc: Simplify writing Cues When the Matroska muxer writes the Cues (the index), it groups index entries with the same timestamp into the same CuePoint to save space. But given Matroska's variable-length length fields, it either needs to have an upper bound of the final size of the CuePoint before writing it or the CuePoint has to be assembled in a different buffer, so that after having assembled the CuePoint (when the real size is known), the CuePoint's header can be written and its data copied after it. The first of these approaches is the currently used one. This entails finding out the number of entries in a CuePoint before starting the CuePoint and therefore means that the list is read at least twice. Furthermore, a worst-case upper-bound for the length of a single entry was used, so that sometimes bytes are wasted on length fields. This commit switches to the second approach. This is no longer more expensive than the current approach if one only resets the dynamic buffer used to write the CuePoint's content instead of opening a new buffer for every CuePoint: Writing the trailer of a file with 540.000 CuePoints improved actually from 219054414 decicycles to 2164379394 decicycles (based upon 50 iterations). Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5e3b7bd56d2c476a508c03e2029675bfd2618122 --- libavformat/matroskaenc.c | 74 +-- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 433a2b5579..a2901e6aa5 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -170,12 +170,8 @@ typedef struct MatroskaMuxContext { * offset, 4 bytes for target EBML ID */ #define MAX_SEEKENTRY_SIZE 21 -/** per-cuepoint-track - 5 1-byte EBML IDs, 5 1-byte EBML sizes, 3 8-byte uint max - * and one 1-byte uint for the track number (this assumes MAX_TRACKS to be <= 255) */ -#define MAX_CUETRACKPOS_SIZE 35 - -/** per-cuepoint - 1 1-byte EBML ID, 1 1-byte EBML size, 8-byte uint max */ -#define MAX_CUEPOINT_CONTENT_SIZE(num_tracks) 10 + MAX_CUETRACKPOS_SIZE * num_tracks +/** 4 * (1-byte EBML ID, 1-byte EBML size, 8-byte uint max) */ +#define MAX_CUETRACKPOS_SIZE 40 /** Seek preroll value for opus */ #define OPUS_SEEK_PREROLL 8000 @@ -506,58 +502,54 @@ static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int tracknum, i static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tracks, int num_tracks) { MatroskaMuxContext *mkv = s->priv_data; -AVIOContext *dyn_cp, *pb = s->pb; +AVIOContext *dyn_cp, *pb = s->pb, *cuepoint; int64_t currentpos; -int i, j, ret; +int ret; currentpos = avio_tell(pb); ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES); if (ret < 0) return ret; -for (i = 0; i < cues->num_entries; i++) { -ebml_master cuepoint, track_positions; -mkv_cuepoint *entry = &cues->entries[i]; -uint64_t pts = entry->pts; -int ctp_nb = 0; - -// Calculate the number of entries, so we know the element size -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 idx = entry[j].stream_idx; +ret = avio_open_dyn_buf(&cuepoint); +if (ret < 0) { +ffio_free_dyn_buf(&dyn_cp); +return ret; +} -av_assert0(idx >= 0 && idx < num_tracks); -if (tracks[idx].has_cue && s->streams[idx]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) -continue; -tracks[idx].has_cue = 1; -ctp_nb ++; -} +for (mkv_cuepoint *entry = cues->entries, *end = entry + cues->num_entries; + entry < end;) { +uint64_t pts = entry->pts; +uint8_t *buf; +int size; -cuepoint = start_ebml_master(dyn_cp, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_CONTENT_SIZE(ctp_nb)); -put_ebml_uint(dyn_cp, MATROSKA_ID_CUETIME, pts); +put_ebml_uint(cuepoint, MATROSKA_ID_CUETIME, pts); // put all the entries from different tracks that have the exact same // timestamp into the same CuePoint -for (j = 0; j < num_tracks; j++) +for (int 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 idx = entry[j].stream_idx; +do { +ebml_master track_positions; +int idx = entry->stream_idx; +av_assert0(idx >= 0 && idx < num_tracks); if (tracks[idx].has_cue && s->streams[idx]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE)
[FFmpeg-cvslog] avformat/matroskaenc: Write level 1 elements in one go
ffmpeg | branch: master | Andreas Rheinhardt | Mon Dec 30 15:59:02 2019 +0100| [d9c21ec63999501afc39ffc26f363245e8624304] | committer: Andreas Rheinhardt avformat/matroskaenc: Write level 1 elements in one go Up until now, writing level 1 elements proceeded as follows: First, the element id was written to the ordinary output AVIOContext and a dynamic buffer was opened for the content of the level 1 element in start_ebml_master_crc32(). Then this buffer was actually used and after it was closed (in end_ebml_master_crc32()), the size field corresponding to the buffer's size was written, after which the actual data was written. This commit changes this: Nothing is written to the main AVIOContext any more in start_ebml_master_crc32(). end_ebml_master_crc32() now writes both the id, the length field as well as the data. This implies that one can start a level 1 element in memory without outputting anything. This is done to enable to test whether enough space has been reserved for the Cues (if space has been reserved for them) before writing them. A large duration between outputting the header and outputting the rest could also break certain streaming usecases like the one from #8578 (which this commit fixes). Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d9c21ec63999501afc39ffc26f363245e8624304 --- libavformat/matroskaenc.c | 60 +-- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index a2901e6aa5..3c490bd05b 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -325,26 +325,26 @@ static void end_ebml_master(AVIOContext *pb, ebml_master master) avio_seek(pb, pos, SEEK_SET); } -static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, - uint32_t elementid) +static int start_ebml_master_crc32(AVIOContext **dyn_cp, MatroskaMuxContext *mkv) { int ret; if ((ret = avio_open_dyn_buf(dyn_cp)) < 0) return ret; -put_ebml_id(pb, elementid); if (mkv->write_crc) put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */ return 0; } -static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv) +static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, + MatroskaMuxContext *mkv, uint32_t id) { uint8_t *buf, crc[4]; int size, skip = 0; +put_ebml_id(pb, id); size = avio_close_dyn_buf(*dyn_cp, &buf); put_ebml_num(pb, size, 0); if (mkv->write_crc) { @@ -362,13 +362,14 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk * Complete ebml master without destroying the buffer, allowing for later updates */ static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, - int64_t *pos) + uint32_t id, int64_t *pos) { uint8_t *buf; int size = avio_get_dyn_buf(*dyn_cp, &buf); *pos = avio_tell(pb); +put_ebml_id(pb, id); put_ebml_num(pb, size, 0); avio_write(pb, buf, size); } @@ -448,7 +449,7 @@ static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, if ((ret64 = avio_seek(pb, seekhead->filepos, SEEK_SET)) < 0) return error_on_seek_failure ? ret64 : 0; -ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD); +ret = start_ebml_master_crc32(&dyn_cp, mkv); if (ret < 0) return ret; @@ -464,7 +465,7 @@ static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, put_ebml_uint(dyn_cp, MATROSKA_ID_SEEKPOSITION, entry->segmentpos); end_ebml_master(dyn_cp, seekentry); } -end_ebml_master_crc32(pb, &dyn_cp, mkv); +end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD); remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb); put_ebml_void(pb, remaining); @@ -507,7 +508,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra int ret; currentpos = avio_tell(pb); -ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES); +ret = start_ebml_master_crc32(&dyn_cp, mkv); if (ret < 0) return ret; @@ -550,7 +551,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra ffio_reset_dyn_buf(cuepoint); } ffio_free_dyn_buf(&cuepoint); -end_ebml_master_crc32(pb, &dyn_cp, mkv); +end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES); return currentpos; } @@ -1372,7 +1373,7 @@ static int mkv_write_tracks(AVFormatContext *s) mkv_add_seekhead_entry(mkv, MATROSKA_ID
[FFmpeg-cvslog] avformat/matroskaenc: Remove unused function parameter
ffmpeg | branch: master | Andreas Rheinhardt | Tue Oct 29 21:04:21 2019 +0100| [907b7f88ca81bad3edf6236a8ffd2b2431694376] | committer: Andreas Rheinhardt avformat/matroskaenc: Remove unused function parameter end_ebml_master_crc32_preliminary() has a MatroskaMuxContext as parameter that isn't used at all. So remove it. Furthermore it doesn't close its dynamic buffer; it just uses the underlying buffer and therefore it only needs a pointer to the dynamic buffer, not a pointer to a pointer. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=907b7f88ca81bad3edf6236a8ffd2b2431694376 --- libavformat/matroskaenc.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 3c490bd05b..1491010bcc 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -361,11 +361,11 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, /** * Complete ebml master without destroying the buffer, allowing for later updates */ -static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, +static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext *dyn_cp, uint32_t id, int64_t *pos) { uint8_t *buf; -int size = avio_get_dyn_buf(*dyn_cp, &buf); +int size = avio_get_dyn_buf(dyn_cp, &buf); *pos = avio_tell(pb); @@ -1388,7 +1388,7 @@ static int mkv_write_tracks(AVFormatContext *s) } if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) -end_ebml_master_crc32_preliminary(pb, &mkv->tracks_bc, mkv, +end_ebml_master_crc32_preliminary(pb, mkv->tracks_bc, MATROSKA_ID_TRACKS, &mkv->tracks_pos); else end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, MATROSKA_ID_TRACKS); @@ -1643,7 +1643,7 @@ static int mkv_write_tags(AVFormatContext *s) if (mkv->tags_bc) { if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) -end_ebml_master_crc32_preliminary(s->pb, &mkv->tags_bc, mkv, +end_ebml_master_crc32_preliminary(s->pb, mkv->tags_bc, MATROSKA_ID_TAGS, &mkv->tags_pos); else end_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS); @@ -1880,7 +1880,7 @@ static int mkv_write_header(AVFormatContext *s) } } if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) -end_ebml_master_crc32_preliminary(s->pb, &mkv->info_bc, mkv, +end_ebml_master_crc32_preliminary(s->pb, mkv->info_bc, MATROSKA_ID_INFO, &mkv->info_pos); else end_ebml_master_crc32(s->pb, &mkv->info_bc, mkv, MATROSKA_ID_INFO); ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/matroskaenc: Check that Cluster has been opened
ffmpeg | branch: master | Andreas Rheinhardt | Tue Nov 26 04:40:29 2019 +0100| [5d24b6843ca548508187d48bf587ae5ecbcffd57] | committer: Andreas Rheinhardt avformat/matroskaenc: Check that Cluster has been opened before setting the field indicating that a Cluster has been opened. Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5d24b6843ca548508187d48bf587ae5ecbcffd57 --- libavformat/matroskaenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 1491010bcc..5dae53026d 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2311,10 +2311,10 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_ } if (mkv->cluster_pos == -1) { -mkv->cluster_pos = avio_tell(s->pb); ret = start_ebml_master_crc32(&mkv->cluster_bc, mkv); if (ret < 0) return ret; +mkv->cluster_pos = avio_tell(s->pb); put_ebml_uint(mkv->cluster_bc, MATROSKA_ID_CLUSTERTIMECODE, FFMAX(0, ts)); mkv->cluster_pts = FFMAX(0, ts); av_log(s, AV_LOG_DEBUG, ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/mxfdec: Correct confusing struct tag
ffmpeg | branch: master | Andreas Rheinhardt | Sun Mar 29 05:33:04 2020 +0200| [8d019dbc5b44361d38575fe0e13ae2a1ab1cde08] | committer: Andreas Rheinhardt avformat/mxfdec: Correct confusing struct tag Don't use typedef struct MXFTrack {...} MXFTimecodeComponent, in particular given the fact that MXFTrack is a type of its own. Reviewed-by: Tomas Härdin Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8d019dbc5b44361d38575fe0e13ae2a1ab1cde08 --- libavformat/mxfdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 3374f36a88..fdd0dd2a88 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -131,7 +131,7 @@ typedef struct MXFSequence { uint8_t origin; } MXFSequence; -typedef struct MXFTrack { +typedef struct MXFTimecodeComponent { UID uid; enum MXFMetadataSetType type; int drop_frame; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/matroskaenc: Write level 1 elements in one go
ffmpeg | branch: release/4.2 | Andreas Rheinhardt | Mon Dec 30 15:59:02 2019 +0100| [477275795865f074e60635d813a7b765284ca948] | committer: Andreas Rheinhardt avformat/matroskaenc: Write level 1 elements in one go Up until now, writing level 1 elements proceeded as follows: First, the element id was written to the ordinary output AVIOContext and a dynamic buffer was opened for the content of the level 1 element in start_ebml_master_crc32(). Then this buffer was actually used and after it was closed (in end_ebml_master_crc32()), the size field corresponding to the buffer's size was written, after which the actual data was written. This commit changes this: Nothing is written to the main AVIOContext any more in start_ebml_master_crc32(). end_ebml_master_crc32() now writes both the id, the length field as well as the data. This is benefical for streaming, because a client that receives just a Cluster ID and nothing more might infer that this is EOF; in certain usecases there is also the danger of a client receiving the Cluster without the actual Cluster ID at the beginning. Addresses #8578. (cherry picked from commit d9c21ec) Signed-off-by: Andreas Rheinhardt > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=477275795865f074e60635d813a7b765284ca948 --- libavformat/matroskaenc.c | 63 +-- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index cef504fa05..2e63b90b28 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -331,26 +331,26 @@ static void end_ebml_master(AVIOContext *pb, ebml_master master) avio_seek(pb, pos, SEEK_SET); } -static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, - uint32_t elementid) +static int start_ebml_master_crc32(AVIOContext **dyn_cp, MatroskaMuxContext *mkv) { int ret; if ((ret = avio_open_dyn_buf(dyn_cp)) < 0) return ret; -put_ebml_id(pb, elementid); if (mkv->write_crc) put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */ return 0; } -static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv) +static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, + MatroskaMuxContext *mkv, uint32_t id) { uint8_t *buf, crc[4]; int size, skip = 0; +put_ebml_id(pb, id); size = avio_close_dyn_buf(*dyn_cp, &buf); put_ebml_num(pb, size, 0); if (mkv->write_crc) { @@ -368,13 +368,14 @@ static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, Matrosk * Complete ebml master without destroying the buffer, allowing for later updates */ static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, - int64_t *pos) + uint32_t id, int64_t *pos) { uint8_t *buf; int size = avio_get_dyn_buf(*dyn_cp, &buf); *pos = avio_tell(pb); +put_ebml_id(pb, id); put_ebml_num(pb, size, 0); avio_write(pb, buf, size); } @@ -500,7 +501,7 @@ static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv) } } -if (start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD) < 0) { +if (start_ebml_master_crc32(&dyn_cp, mkv) < 0) { currentpos = -1; goto fail; } @@ -517,7 +518,7 @@ static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv) put_ebml_uint(dyn_cp, MATROSKA_ID_SEEKPOSITION, entry->segmentpos); end_ebml_master(dyn_cp, seekentry); } -end_ebml_master_crc32(pb, &dyn_cp, mkv); +end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD); if (seekhead->reserved_size > 0) { uint64_t remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb); @@ -574,7 +575,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra int i, j, ret; currentpos = avio_tell(pb); -ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES); +ret = start_ebml_master_crc32(&dyn_cp, mkv); if (ret < 0) return ret; @@ -620,7 +621,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra i += j - 1; end_ebml_master(dyn_cp, cuepoint); } -end_ebml_master_crc32(pb, &dyn_cp, mkv); +end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES); return currentpos; } @@ -1450,7 +1451,7 @@ static int mkv_write_tracks(AVFormatContext *s) if (ret < 0) return ret; -ret = start_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, MATROSKA_ID_TRACKS); +ret = start_ebml_master_crc32(&mkv->tracks_bc, mkv);
[FFmpeg-cvslog] avformat/dashdec: Don't allocate and leak strings that are never used
ffmpeg | branch: release/4.2 | Andreas Rheinhardt | Sun Mar 29 01:32:34 2020 +0100| [3eedf1599be64fbbb092045fb24e5b22e1149a43] | committer: Andreas Rheinhardt avformat/dashdec: Don't allocate and leak strings that are never used Since commit e134c203 strdups of several elements of a manifest are kept in the DASHContext; but said commit completely forgot to free these strings again (with xmlFree()). Given that these strings are never used at all, this commit closes this leak by reverting said commit. This reverts commit e134c20374ee3cbc6d04885d306b02c9871683a2. Signed-off-by: Andreas Rheinhardt (cherry picked from commit 3c138e5ceb487490f88015b1694ce34c1393736c) > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3eedf1599be64fbbb092045fb24e5b22e1149a43 --- libavformat/dashdec.c | 27 --- 1 file changed, 27 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index f82a750d6f..c45f058088 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -122,19 +122,6 @@ struct representation { typedef struct DASHContext { const AVClass *class; char *base_url; -char *adaptionset_contenttype_val; -char *adaptionset_par_val; -char *adaptionset_lang_val; -char *adaptionset_minbw_val; -char *adaptionset_maxbw_val; -char *adaptionset_minwidth_val; -char *adaptionset_maxwidth_val; -char *adaptionset_minheight_val; -char *adaptionset_maxheight_val; -char *adaptionset_minframerate_val; -char *adaptionset_maxframerate_val; -char *adaptionset_segmentalignment_val; -char *adaptionset_bitstreamswitching_val; int n_videos; struct representation **videos; @@ -1107,26 +1094,12 @@ static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, xmlNodePtr period_segmentlist_node) { int ret = 0; -DASHContext *c = s->priv_data; xmlNodePtr fragment_template_node = NULL; xmlNodePtr content_component_node = NULL; xmlNodePtr adaptionset_baseurl_node = NULL; xmlNodePtr adaptionset_segmentlist_node = NULL; xmlNodePtr adaptionset_supplementalproperty_node = NULL; xmlNodePtr node = NULL; -c->adaptionset_contenttype_val = xmlGetProp(adaptionset_node, "contentType"); -c->adaptionset_par_val = xmlGetProp(adaptionset_node, "par"); -c->adaptionset_lang_val = xmlGetProp(adaptionset_node, "lang"); -c->adaptionset_minbw_val = xmlGetProp(adaptionset_node, "minBandwidth"); -c->adaptionset_maxbw_val = xmlGetProp(adaptionset_node, "maxBandwidth"); -c->adaptionset_minwidth_val = xmlGetProp(adaptionset_node, "minWidth"); -c->adaptionset_maxwidth_val = xmlGetProp(adaptionset_node, "maxWidth"); -c->adaptionset_minheight_val = xmlGetProp(adaptionset_node, "minHeight"); -c->adaptionset_maxheight_val = xmlGetProp(adaptionset_node, "maxHeight"); -c->adaptionset_minframerate_val = xmlGetProp(adaptionset_node, "minFrameRate"); -c->adaptionset_maxframerate_val = xmlGetProp(adaptionset_node, "maxFrameRate"); -c->adaptionset_segmentalignment_val = xmlGetProp(adaptionset_node, "segmentAlignment"); -c->adaptionset_bitstreamswitching_val = xmlGetProp(adaptionset_node, "bitstreamSwitching"); node = xmlFirstElementChild(adaptionset_node); while (node) { ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avformat/dashdec: Don't allocate and leak strings that are never used
ffmpeg | branch: release/4.1 | Andreas Rheinhardt | Sun Mar 29 01:32:34 2020 +0100| [de3d708dbf6dd2982dfde48c002463759ca6945b] | committer: Andreas Rheinhardt avformat/dashdec: Don't allocate and leak strings that are never used Since commit e134c203 strdups of several elements of a manifest are kept in the DASHContext; but said commit completely forgot to free these strings again (with xmlFree()). Given that these strings are never used at all, this commit closes this leak by reverting said commit. This reverts commit e134c20374ee3cbc6d04885d306b02c9871683a2. Signed-off-by: Andreas Rheinhardt (cherry picked from commit 3c138e5ceb487490f88015b1694ce34c1393736c) > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=de3d708dbf6dd2982dfde48c002463759ca6945b --- libavformat/dashdec.c | 27 --- 1 file changed, 27 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 497e7e469c..2283b2438a 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -122,19 +122,6 @@ struct representation { typedef struct DASHContext { const AVClass *class; char *base_url; -char *adaptionset_contenttype_val; -char *adaptionset_par_val; -char *adaptionset_lang_val; -char *adaptionset_minbw_val; -char *adaptionset_maxbw_val; -char *adaptionset_minwidth_val; -char *adaptionset_maxwidth_val; -char *adaptionset_minheight_val; -char *adaptionset_maxheight_val; -char *adaptionset_minframerate_val; -char *adaptionset_maxframerate_val; -char *adaptionset_segmentalignment_val; -char *adaptionset_bitstreamswitching_val; int n_videos; struct representation **videos; @@ -1080,26 +1067,12 @@ static int parse_manifest_adaptationset(AVFormatContext *s, const char *url, xmlNodePtr period_segmentlist_node) { int ret = 0; -DASHContext *c = s->priv_data; xmlNodePtr fragment_template_node = NULL; xmlNodePtr content_component_node = NULL; xmlNodePtr adaptionset_baseurl_node = NULL; xmlNodePtr adaptionset_segmentlist_node = NULL; xmlNodePtr adaptionset_supplementalproperty_node = NULL; xmlNodePtr node = NULL; -c->adaptionset_contenttype_val = xmlGetProp(adaptionset_node, "contentType"); -c->adaptionset_par_val = xmlGetProp(adaptionset_node, "par"); -c->adaptionset_lang_val = xmlGetProp(adaptionset_node, "lang"); -c->adaptionset_minbw_val = xmlGetProp(adaptionset_node, "minBandwidth"); -c->adaptionset_maxbw_val = xmlGetProp(adaptionset_node, "maxBandwidth"); -c->adaptionset_minwidth_val = xmlGetProp(adaptionset_node, "minWidth"); -c->adaptionset_maxwidth_val = xmlGetProp(adaptionset_node, "maxWidth"); -c->adaptionset_minheight_val = xmlGetProp(adaptionset_node, "minHeight"); -c->adaptionset_maxheight_val = xmlGetProp(adaptionset_node, "maxHeight"); -c->adaptionset_minframerate_val = xmlGetProp(adaptionset_node, "minFrameRate"); -c->adaptionset_maxframerate_val = xmlGetProp(adaptionset_node, "maxFrameRate"); -c->adaptionset_segmentalignment_val = xmlGetProp(adaptionset_node, "segmentAlignment"); -c->adaptionset_bitstreamswitching_val = xmlGetProp(adaptionset_node, "bitstreamSwitching"); node = xmlFirstElementChild(adaptionset_node); while (node) { ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".