summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2014-10-02 20:59:20 +0000
committerjstebbins <[email protected]>2014-10-02 20:59:20 +0000
commit9254fa47939e055f39f1cd5f8db52268d498558d (patch)
tree21152ef75c6b0410e5852ca98dd98a00ffde161f /libhb
parentfc2a484c244a4d922b2621c1f986bec289194517 (diff)
libhb: simplify avcodec extradata parsing
Use avcodec parser->split() instead of writing our own parser. This makes extradata parsing work for stream formats other than vc1 if the need should ever arise. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6429 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r--libhb/decavcodec.c96
1 files changed, 21 insertions, 75 deletions
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c
index 129b43f2f..e235111d8 100644
--- a/libhb/decavcodec.c
+++ b/libhb/decavcodec.c
@@ -508,7 +508,7 @@ static void closePrivData( hb_work_private_t ** ppv )
}
#endif
- free( pv );
+ free(pv);
}
*ppv = NULL;
}
@@ -1708,37 +1708,6 @@ static int decavcodecvInit( hb_work_object_t * w, hb_job_t * job )
return 0;
}
-static int next_hdr( hb_buffer_t *in, int offset )
-{
- uint8_t *dat = in->data;
- uint16_t last2 = 0xffff;
- for ( ; in->size - offset > 1; ++offset )
- {
- if ( last2 == 0 && dat[offset] == 0x01 )
- // found an mpeg start code
- return offset - 2;
-
- last2 = ( last2 << 8 ) | dat[offset];
- }
-
- return -1;
-}
-
-static int find_hdr( hb_buffer_t *in, int offset, uint8_t hdr_type )
-{
- if ( in->size - offset < 4 )
- // not enough room for an mpeg start code
- return -1;
-
- for ( ; ( offset = next_hdr( in, offset ) ) >= 0; ++offset )
- {
- if ( in->data[offset+3] == hdr_type )
- // found it
- break;
- }
- return offset;
-}
-
static int setup_extradata( hb_work_object_t *w, hb_buffer_t *in )
{
hb_work_private_t *pv = w->private_data;
@@ -1748,53 +1717,30 @@ static int setup_extradata( hb_work_object_t *w, hb_buffer_t *in )
// vc1t_read_header allocates 'extradata' to deal with header issues
// related to Microsoft's bizarre engineering notions. We alloc a chunk
// of space to make vc1 work then associate the codec with the context.
- if ( w->codec_param != AV_CODEC_ID_VC1 )
- {
- // we haven't been inflicted with M$ - allocate a little space as
- // a marker and return success.
- pv->context->extradata_size = 0;
- // av_malloc uses posix_memalign which is allowed to
- // return NULL when allocating 0 bytes. We use extradata == NULL
- // to trigger initialization of extradata and the decoder, so
- // we can not set it to NULL here. So allocate a small
- // buffer instead.
- pv->context->extradata = av_malloc(1);
- return 0;
- }
-
- // find the start and and of the sequence header
- int shdr, shdr_end;
- if ( ( shdr = find_hdr( in, 0, 0x0f ) ) < 0 )
- {
- // didn't find start of seq hdr
- return 1;
- }
- if ( ( shdr_end = next_hdr( in, shdr + 4 ) ) < 0 )
+ if (pv->context->extradata == NULL)
{
- shdr_end = in->size;
- }
- shdr_end -= shdr;
-
- // find the start and and of the entry point header
- int ehdr, ehdr_end;
- if ( ( ehdr = find_hdr( in, 0, 0x0e ) ) < 0 )
- {
- // didn't find start of entry point hdr
+ if (pv->parser == NULL || pv->parser == NULL ||
+ pv->parser->parser->split == NULL)
+ {
+ return 0;
+ }
+ else
+ {
+ int size;
+ size = pv->parser->parser->split(pv->context, in->data, in->size);
+ if (size > 0)
+ {
+ pv->context->extradata_size = size;
+ pv->context->extradata = av_malloc(size);
+ if (pv->context->extradata == NULL)
+ return 1;
+ memcpy(pv->context->extradata, in->data, size);
+ return 0;
+ }
+ }
return 1;
}
- if ( ( ehdr_end = next_hdr( in, ehdr + 4 ) ) < 0 )
- {
- ehdr_end = in->size;
- }
- ehdr_end -= ehdr;
- // found both headers - allocate an extradata big enough to hold both
- // then copy them into it.
- pv->context->extradata_size = shdr_end + ehdr_end;
- pv->context->extradata = av_malloc(pv->context->extradata_size + 8);
- memcpy( pv->context->extradata, in->data + shdr, shdr_end );
- memcpy( pv->context->extradata + shdr_end, in->data + ehdr, ehdr_end );
- memset( pv->context->extradata + shdr_end + ehdr_end, 0, 8);
return 0;
}