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
1488 MXFStreamContext *sc = st->priv_data;1488 MXFStreamContext *sc = st->priv_data;
1489 AVIOContext *pb = s->pb;1489 AVIOContext *pb = s->pb;
1490 int64_t pos;1490 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 }
1492 1497
1493 /* JPEG2000 subdescriptor key */1498 /* JPEG2000 subdescriptor key */
1494 avio_write(pb, mxf_jpeg2000_subdescriptor_key, 16);1499 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
1527 avio_wb32(pb, sc->j2k_info.j2k_yt0siz);1532 avio_wb32(pb, sc->j2k_info.j2k_yt0siz);
1528 /* Image components number (Csiz) */1533 /* Image components number (Csiz) */
1529 mxf_write_local_tag(s, 2, 0x840A);1534 mxf_write_local_tag(s, 2, 0x840A);
1530 avio_wb16(pb, component_count);1535 avio_wb16(pb, pix_desc->nb_components);
1531 /* Array of picture components where each component comprises 3 bytes named Ssiz(i) (Pixel bitdepth - 1),1536 /* Array of picture components where each component comprises 3 bytes named Ssiz(i) (Pixel bitdepth - 1),
1532 XRSiz(i) (Horizontal sampling), YRSiz(i) (Vertical sampling). The array of 3-byte groups is preceded1537 XRSiz(i) (Horizontal sampling), YRSiz(i) (Vertical sampling). The array of 3-byte groups is preceded
1533 by the array header comprising a 4-byte value of the number of components followed by a 4-byte1538 by the array header comprising a 4-byte value of the number of components followed by a 4-byte
1534 value of 3. */1539 value of 3. */
1535 mxf_write_local_tag(s, 8 + 3*component_count, 0x840B);1540 mxf_write_local_tag(s, 8 + 3*pix_desc->nb_components, 0x840B);
1536 avio_wb32(pb, component_count);1541 avio_wb32(pb, pix_desc->nb_components);
1537 avio_wb32(pb, 3);1542 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);
1539 1544
1540 mxf_update_klv_size(pb, pos);1545 mxf_update_klv_size(pb, pos);
1541}1546}
@@ -2638,10 +2643,15 @@ static int mxf_parse_jpeg2000_frame(AVFormatContext *s, AVStream *st, AVPacket * · 1096 unmodified lines
2638{2643{
2639 MXFContext *mxf = s->priv_data;2644 MXFContext *mxf = s->priv_data;
2640 MXFStreamContext *sc = st->priv_data;2645 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);
2642 GetByteContext g;2647 GetByteContext g;
2643 uint32_t j2k_ncomponents;2648 uint32_t j2k_ncomponents;
2644 2649
2650 if (!pix_desc) {
2651 av_log(s, AV_LOG_ERROR, "Pixel format not set\n");
2652 return AVERROR(EINVAL);
2653 }
2654
2645 if (mxf->header_written)2655 if (mxf->header_written)
2646 return 1;2656 return 1;
2647 2657
@@ -2671,7 +2681,7 @@ static int mxf_parse_jpeg2000_frame(AVFormatContext *s, AVStream *st, AVPacket * · 23 unmodified lines
2671 sc->j2k_info.j2k_xt0siz = bytestream2_get_be32u(&g);2681 sc->j2k_info.j2k_xt0siz = bytestream2_get_be32u(&g);
2672 sc->j2k_info.j2k_yt0siz = bytestream2_get_be32u(&g);2682 sc->j2k_info.j2k_yt0siz = bytestream2_get_be32u(&g);
2673 j2k_ncomponents = bytestream2_get_be16u(&g);2683 j2k_ncomponents = bytestream2_get_be16u(&g);
2674 if (j2k_ncomponents != component_count) {2684 if (j2k_ncomponents != pix_desc->nb_components) {
2675 av_log(s, AV_LOG_ERROR, "Incoherence about components image number.\n");2685 av_log(s, AV_LOG_ERROR, "Incoherence about components image number.\n");
2676 return AVERROR_INVALIDDATA;2686 return AVERROR_INVALIDDATA;
2677 }2687 }

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