[FFmpeg-devel] [PATCH] avcodec/dca: remove GetBitContext usage from avpriv_dca_parse_core_frame_header()
James Almer
jamrial at gmail.com
Wed Jul 19 22:43:58 EEST 2017
This prevents potential ABI issues with GetBitContext.
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavcodec/dca.c | 12 +++++++++++-
libavcodec/dca.h | 7 +++++--
libavcodec/dca_core.c | 2 +-
libavcodec/dca_parser.c | 4 +---
libavformat/dtsdec.c | 4 +---
5 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/libavcodec/dca.c b/libavcodec/dca.c
index 39f8f3d81c..307b21471e 100644
--- a/libavcodec/dca.c
+++ b/libavcodec/dca.c
@@ -88,7 +88,7 @@ int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
}
}
-int avpriv_dca_parse_core_frame_header(GetBitContext *gb, DCACoreFrameHeader *h)
+int ff_dca_parse_core_frame_header(DCACoreFrameHeader *h, GetBitContext *gb)
{
if (get_bits_long(gb, 32) != DCA_SYNCWORD_CORE_BE)
return DCA_PARSE_ERROR_SYNC_WORD;
@@ -145,3 +145,13 @@ int avpriv_dca_parse_core_frame_header(GetBitContext *gb, DCACoreFrameHeader *h)
h->dn_code = get_bits(gb, 4);
return 0;
}
+
+int avpriv_dca_parse_core_frame_header(DCACoreFrameHeader *h, uint8_t *buf, int size)
+{
+ GetBitContext gb;
+
+ if (init_get_bits8(&gb, buf, size) < 0)
+ return DCA_PARSE_ERROR_INVALIDDATA;
+
+ return ff_dca_parse_core_frame_header(h, &gb);
+}
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index cf6204e554..172c965b3b 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -45,7 +45,8 @@ enum DCAParseError {
DCA_PARSE_ERROR_SAMPLE_RATE = -6,
DCA_PARSE_ERROR_RESERVED_BIT = -7,
DCA_PARSE_ERROR_LFE_FLAG = -8,
- DCA_PARSE_ERROR_PCM_RES = -9
+ DCA_PARSE_ERROR_PCM_RES = -9,
+ DCA_PARSE_ERROR_INVALIDDATA = -10,
};
typedef struct DCACoreFrameHeader {
@@ -212,6 +213,8 @@ int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
* Parse and validate core frame header
* @return 0 on success, negative DCA_PARSE_ERROR_ code on failure
*/
-int avpriv_dca_parse_core_frame_header(GetBitContext *gb, DCACoreFrameHeader *h);
+int avpriv_dca_parse_core_frame_header(DCACoreFrameHeader *h, uint8_t *buf, int size);
+
+int ff_dca_parse_core_frame_header(DCACoreFrameHeader *h, GetBitContext *gb);
#endif /* AVCODEC_DCA_H */
diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 3add9f812b..6cb1f30a3c 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -82,7 +82,7 @@ static void get_array(GetBitContext *s, int32_t *array, int size, int n)
static int parse_frame_header(DCACoreDecoder *s)
{
DCACoreFrameHeader h = { 0 };
- int err = avpriv_dca_parse_core_frame_header(&s->gb, &h);
+ int err = ff_dca_parse_core_frame_header(&h, &s->gb);
if (err < 0) {
switch (err) {
diff --git a/libavcodec/dca_parser.c b/libavcodec/dca_parser.c
index 7e99b16bf0..11ddb8f188 100644
--- a/libavcodec/dca_parser.c
+++ b/libavcodec/dca_parser.c
@@ -263,9 +263,7 @@ static int dca_parse_params(DCAParseContext *pc1, const uint8_t *buf,
if ((ret = avpriv_dca_convert_bitstream(buf, DCA_CORE_FRAME_HEADER_SIZE,
hdr, DCA_CORE_FRAME_HEADER_SIZE)) < 0)
return ret;
- if ((ret = init_get_bits8(&gb, hdr, ret)) < 0)
- return ret;
- if (avpriv_dca_parse_core_frame_header(&gb, &h) < 0)
+ if (avpriv_dca_parse_core_frame_header(&h, hdr, ret) < 0)
return AVERROR_INVALIDDATA;
*duration = h.npcmblocks * DCA_PCMBLOCK_SAMPLES;
diff --git a/libavformat/dtsdec.c b/libavformat/dtsdec.c
index 6e0048f9bc..a3e52cd596 100644
--- a/libavformat/dtsdec.c
+++ b/libavformat/dtsdec.c
@@ -101,9 +101,7 @@ static int dts_probe(AVProbeData *p)
if ((ret = avpriv_dca_convert_bitstream(buf - 2, DCA_CORE_FRAME_HEADER_SIZE,
hdr, DCA_CORE_FRAME_HEADER_SIZE)) < 0)
continue;
- if (init_get_bits8(&gb, hdr, ret) < 0)
- continue;
- if (avpriv_dca_parse_core_frame_header(&gb, &h) < 0)
+ if (avpriv_dca_parse_core_frame_header(&h, hdr, ret) < 0)
continue;
marker += 4 * h.sr_code;
--
2.13.3
More information about the ffmpeg-devel
mailing list