It represents the relationship between them more naturally and will be
useful in the following commits.
---
libavcodec/h264_ps.c | 29 +++++++++++++++++++++++++----
libavcodec/h264_ps.h | 2 ++
libavcodec/h264_slice.c | 4 ++--
3 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index b3a0e8a..ba6e371 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -663,6 +663,15 @@ static void build_qp_table(PPS *pps, int t, int index,
const int depth)
ff_h264_chroma_qp[depth - 8][av_clip(i + index, 0, max_qp)];
}
+static void pps_free(void *opaque, uint8_t *data)
+{
+ PPS *pps = (PPS*)data;
+
+ av_buffer_unref(&pps->sps_buf);
+
+ av_freep(&data);
+}
+
int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext
*avctx,
H264ParamSets *ps, int bit_length)
{
@@ -679,10 +688,16 @@ int ff_h264_decode_picture_parameter_set(GetBitContext
*gb, AVCodecContext *avct
return AVERROR_INVALIDDATA;
}
- pps_buf = av_buffer_allocz(sizeof(*pps));
- if (!pps_buf)
+ pps = av_mallocz(sizeof(*pps));
+ if (!pps)
return AVERROR(ENOMEM);
- pps = (PPS*)pps_buf->data;
+
+ pps_buf = av_buffer_create((uint8_t*)pps, sizeof(*pps),
+ pps_free, NULL, 0);
+ if (!pps_buf) {
+ av_freep(&pps);
+ return AVERROR(ENOMEM);
+ }
pps->sps_id = get_ue_golomb_31(gb);
if ((unsigned)pps->sps_id >= MAX_SPS_COUNT ||
@@ -691,7 +706,13 @@ int ff_h264_decode_picture_parameter_set(GetBitContext
*gb, AVCodecContext *avct
ret = AVERROR_INVALIDDATA;
goto fail;
}
- sps = (SPS*)ps->sps_list[pps->sps_id]->data;
+
+ pps->sps_buf = av_buffer_ref(ps->sps_list[pps->sps_id]);
+ if (!pps->sps_buf) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+ sps = (SPS*)pps->sps_buf->data;
if (sps->bit_depth_luma > 10) {
avpriv_report_missing_feature(avctx, "Luma bit depth=%d (max=10)",
diff --git a/libavcodec/h264_ps.h b/libavcodec/h264_ps.h
index 9a32d93..c0ff98c 100644
--- a/libavcodec/h264_ps.h
+++ b/libavcodec/h264_ps.h
@@ -128,6 +128,8 @@ typedef struct PPS {
uint32_t dequant8_buffer[6][QP_MAX_NUM + 1][64];
uint32_t(*dequant4_coeff[6])[16];
uint32_t(*dequant8_coeff[6])[64];
+
+ AVBufferRef *sps_buf;
} PPS;
typedef struct H264ParamSets {
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 19f5d37..705baa0 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -916,8 +916,8 @@ static int h264_init_ps(H264Context *h, const
H264SliceContext *sl)
int needs_reinit = 0, ret;
h->ps.pps = (const PPS*)h->ps.pps_list[sl->pps_id]->data;
- if (h->ps.sps != (const SPS*)h->ps.sps_list[h->ps.pps->sps_id]->data) {
- h->ps.sps = (SPS*)h->ps.sps_list[h->ps.pps->sps_id]->data;
+ if (h->ps.sps != (const SPS*)h->ps.pps->sps_buf->data) {
+ h->ps.sps = (SPS*)h->ps.pps->sps_buf->data;
if (h->bit_depth_luma != h->ps.sps->bit_depth_luma ||
h->chroma_format_idc != h->ps.sps->chroma_format_idc)
--
2.0.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel