History

lavf/mxfenc: Use nb_components, not av_pix_fmt_count_planes()

Also check that pix_desc != NULL, thanks James Almer This fixes https://trac.ffmpeg.org/ticket/11267

Tomas Härdin committed 2 years ago

Commit 733d8911 parent f4ba5b01 file · +17 −7Browse files

Unified · Split

libavformat/mxfenc.c+17−7
@@ -1488,7 +1488,12 @@ static void mxf_write_jpeg2000_subdesc(AVFormatContext *s, AVStream *st) · 1487 unmodified lines
14881488 MXFStreamContext *sc = st->priv_data;
14891489 AVIOContext *pb = s->pb;
14901490 int64_t pos;
1491− int component_count = av_pix_fmt_count_planes(st->codecpar->format);
1491+ const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
1492+
1493+ if (!pix_desc) {
1494+ av_log(s, AV_LOG_ERROR, "Pixel format not set - not writing JPEG2000SubDescriptor\n");
1495+ return;
1496+ }
14921497
14931498 /* JPEG2000 subdescriptor key */
14941499 avio_write(pb, mxf_jpeg2000_subdescriptor_key, 16);
@@ -1527,15 +1532,15 @@ static void mxf_write_jpeg2000_subdesc(AVFormatContext *s, AVStream *st) · 32 unmodified lines
15271532 avio_wb32(pb, sc->j2k_info.j2k_yt0siz);
15281533 /* Image components number (Csiz) */
15291534 mxf_write_local_tag(s, 2, 0x840A);
1530− avio_wb16(pb, component_count);
1535+ avio_wb16(pb, pix_desc->nb_components);
15311536 /* Array of picture components where each component comprises 3 bytes named Ssiz(i) (Pixel bitdepth - 1),
15321537 XRSiz(i) (Horizontal sampling), YRSiz(i) (Vertical sampling). The array of 3-byte groups is preceded
15331538 by the array header comprising a 4-byte value of the number of components followed by a 4-byte
15341539 value of 3. */
1535− mxf_write_local_tag(s, 8 + 3*component_count, 0x840B);
1536− avio_wb32(pb, component_count);
1540+ mxf_write_local_tag(s, 8 + 3*pix_desc->nb_components, 0x840B);
1541+ avio_wb32(pb, pix_desc->nb_components);
15371542 avio_wb32(pb, 3);
1538− avio_write(pb, sc->j2k_info.j2k_comp_desc, 3*component_count);
1543+ avio_write(pb, sc->j2k_info.j2k_comp_desc, 3*pix_desc->nb_components);
15391544
15401545 mxf_update_klv_size(pb, pos);
15411546 }
@@ -2638,10 +2643,15 @@ static int mxf_parse_jpeg2000_frame(AVFormatContext *s, AVStream *st, AVPacket * · 1096 unmodified lines
26382643 {
26392644 MXFContext *mxf = s->priv_data;
26402645 MXFStreamContext *sc = st->priv_data;
2641− int component_count = av_pix_fmt_count_planes(st->codecpar->format);
2646+ const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format);
26422647 GetByteContext g;
26432648 uint32_t j2k_ncomponents;
26442649
2650+ if (!pix_desc) {
2651+ av_log(s, AV_LOG_ERROR, "Pixel format not set\n");
2652+ return AVERROR(EINVAL);
2653+ }
2654+
26452655 if (mxf->header_written)
26462656 return 1;
26472657
@@ -2671,7 +2681,7 @@ static int mxf_parse_jpeg2000_frame(AVFormatContext *s, AVStream *st, AVPacket * · 23 unmodified lines
26712681 sc->j2k_info.j2k_xt0siz = bytestream2_get_be32u(&g);
26722682 sc->j2k_info.j2k_yt0siz = bytestream2_get_be32u(&g);
26732683 j2k_ncomponents = bytestream2_get_be16u(&g);
2674− if (j2k_ncomponents != component_count) {
2684+ if (j2k_ncomponents != pix_desc->nb_components) {
26752685 av_log(s, AV_LOG_ERROR, "Incoherence about components image number.\n");
26762686 return AVERROR_INVALIDDATA;
26772687 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t