Originally committed as revision 12894 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -29,34 +29,40 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1, |
| 29 | 29 |
const uint8_t *buf, int buf_size) |
| 30 | 30 |
{
|
| 31 | 31 |
AACAC3ParseContext *s = s1->priv_data; |
| 32 |
- const uint8_t *buf_ptr; |
|
| 33 |
- int len; |
|
| 32 |
+ ParseContext *pc = &s->pc; |
|
| 33 |
+ int len, i; |
|
| 34 | 34 |
|
| 35 |
- *poutbuf = NULL; |
|
| 36 |
- *poutbuf_size = 0; |
|
| 35 |
+ i=END_NOT_FOUND; |
|
| 36 |
+ if(s->remaining_size <= buf_size){
|
|
| 37 |
+ if(s->remaining_size){
|
|
| 38 |
+ i= s->remaining_size; |
|
| 39 |
+ s->remaining_size = 0; |
|
| 40 |
+ }else{ //we need a header first
|
|
| 41 |
+ len=0; |
|
| 42 |
+ for(i=s->remaining_size; i<buf_size; i++){
|
|
| 43 |
+ s->state = (s->state<<8) + buf[i]; |
|
| 44 |
+ if((len=s->sync(s->state, s))) |
|
| 45 |
+ break; |
|
| 46 |
+ } |
|
| 47 |
+ if(len<=0){
|
|
| 48 |
+ i=END_NOT_FOUND; |
|
| 49 |
+ }else{
|
|
| 50 |
+ i-= s->header_size -1; |
|
| 51 |
+ s->remaining_size = len + i; |
|
| 52 |
+ } |
|
| 53 |
+ } |
|
| 54 |
+ } |
|
| 37 | 55 |
|
| 38 |
- buf_ptr = buf; |
|
| 39 |
- while (buf_size > 0) {
|
|
| 40 |
- int size_needed= s->frame_size ? s->frame_size : s->header_size; |
|
| 41 |
- len = s->inbuf_ptr - s->inbuf; |
|
| 56 |
+ if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
|
|
| 57 |
+ s->remaining_size -= FFMIN(s->remaining_size, buf_size); |
|
| 58 |
+ *poutbuf = NULL; |
|
| 59 |
+ *poutbuf_size = 0; |
|
| 60 |
+ return buf_size; |
|
| 61 |
+ } |
|
| 42 | 62 |
|
| 43 |
- if(len<size_needed){
|
|
| 44 |
- len = FFMIN(size_needed - len, buf_size); |
|
| 45 |
- memcpy(s->inbuf_ptr, buf_ptr, len); |
|
| 46 |
- buf_ptr += len; |
|
| 47 |
- s->inbuf_ptr += len; |
|
| 48 |
- buf_size -= len; |
|
| 49 |
- } |
|
| 63 |
+ *poutbuf = buf; |
|
| 64 |
+ *poutbuf_size = buf_size; |
|
| 50 | 65 |
|
| 51 |
- if (s->frame_size == 0) {
|
|
| 52 |
- if ((s->inbuf_ptr - s->inbuf) == s->header_size) {
|
|
| 53 |
- len = s->sync(s); |
|
| 54 |
- if (len == 0) {
|
|
| 55 |
- /* no sync found : move by one byte (inefficient, but simple!) */ |
|
| 56 |
- memmove(s->inbuf, s->inbuf + 1, s->header_size - 1); |
|
| 57 |
- s->inbuf_ptr--; |
|
| 58 |
- } else {
|
|
| 59 |
- s->frame_size = len; |
|
| 60 | 66 |
/* update codec info */ |
| 61 | 67 |
avctx->sample_rate = s->sample_rate; |
| 62 | 68 |
/* allow downmixing to stereo (or mono for AC3) */ |
| ... | ... |
@@ -71,17 +77,6 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1, |
| 71 | 71 |
} |
| 72 | 72 |
avctx->bit_rate = s->bit_rate; |
| 73 | 73 |
avctx->frame_size = s->samples; |
| 74 |
- } |
|
| 75 |
- } |
|
| 76 |
- } else {
|
|
| 77 |
- if(s->inbuf_ptr - s->inbuf == s->frame_size){
|
|
| 78 |
- *poutbuf = s->inbuf; |
|
| 79 |
- *poutbuf_size = s->frame_size; |
|
| 80 |
- s->inbuf_ptr = s->inbuf; |
|
| 81 |
- s->frame_size = 0; |
|
| 82 |
- break; |
|
| 83 |
- } |
|
| 84 |
- } |
|
| 85 |
- } |
|
| 86 |
- return buf_ptr - buf; |
|
| 74 |
+ |
|
| 75 |
+ return i; |
|
| 87 | 76 |
} |
| ... | ... |
@@ -27,16 +27,18 @@ |
| 27 | 27 |
#include "avcodec.h" |
| 28 | 28 |
|
| 29 | 29 |
typedef struct AACAC3ParseContext {
|
| 30 |
- uint8_t *inbuf_ptr; |
|
| 31 | 30 |
int frame_size; |
| 32 | 31 |
int header_size; |
| 33 |
- int (*sync)(struct AACAC3ParseContext *hdr_info); |
|
| 34 |
- uint8_t inbuf[8192]; /* input buffer */ |
|
| 32 |
+ int (*sync)(uint64_t state, struct AACAC3ParseContext *hdr_info); |
|
| 35 | 33 |
|
| 36 | 34 |
int channels; |
| 37 | 35 |
int sample_rate; |
| 38 | 36 |
int bit_rate; |
| 39 | 37 |
int samples; |
| 38 |
+ |
|
| 39 |
+ ParseContext pc; |
|
| 40 |
+ int remaining_size; |
|
| 41 |
+ uint64_t state; |
|
| 40 | 42 |
} AACAC3ParseContext; |
| 41 | 43 |
|
| 42 | 44 |
int ff_aac_ac3_parse(AVCodecParserContext *s1, |
| ... | ... |
@@ -27,12 +27,13 @@ |
| 27 | 27 |
|
| 28 | 28 |
#define AAC_HEADER_SIZE 7 |
| 29 | 29 |
|
| 30 |
-static int aac_sync(AACAC3ParseContext *hdr_info) |
|
| 30 |
+static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info) |
|
| 31 | 31 |
{
|
| 32 | 32 |
GetBitContext bits; |
| 33 | 33 |
int size, rdb, ch, sr; |
| 34 |
+ uint64_t tmp = be2me_64(state); |
|
| 34 | 35 |
|
| 35 |
- init_get_bits(&bits, hdr_info->inbuf, AAC_HEADER_SIZE * 8); |
|
| 36 |
+ init_get_bits(&bits, ((uint8_t *)&tmp)+8-AAC_HEADER_SIZE, AAC_HEADER_SIZE * 8); |
|
| 36 | 37 |
|
| 37 | 38 |
if(get_bits(&bits, 12) != 0xfff) |
| 38 | 39 |
return 0; |
| ... | ... |
@@ -72,7 +73,6 @@ static int aac_sync(AACAC3ParseContext *hdr_info) |
| 72 | 72 |
static av_cold int aac_parse_init(AVCodecParserContext *s1) |
| 73 | 73 |
{
|
| 74 | 74 |
AACAC3ParseContext *s = s1->priv_data; |
| 75 |
- s->inbuf_ptr = s->inbuf; |
|
| 76 | 75 |
s->header_size = AAC_HEADER_SIZE; |
| 77 | 76 |
s->sync = aac_sync; |
| 78 | 77 |
return 0; |
| ... | ... |
@@ -123,12 +123,13 @@ int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr) |
| 123 | 123 |
return 0; |
| 124 | 124 |
} |
| 125 | 125 |
|
| 126 |
-static int ac3_sync(AACAC3ParseContext *hdr_info) |
|
| 126 |
+static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info) |
|
| 127 | 127 |
{
|
| 128 | 128 |
int err; |
| 129 |
+ uint64_t tmp = be2me_64(state); |
|
| 129 | 130 |
AC3HeaderInfo hdr; |
| 130 | 131 |
|
| 131 |
- err = ff_ac3_parse_header(hdr_info->inbuf, &hdr); |
|
| 132 |
+ err = ff_ac3_parse_header(((uint8_t *)&tmp)+8-AC3_HEADER_SIZE, &hdr); |
|
| 132 | 133 |
|
| 133 | 134 |
if(err < 0) |
| 134 | 135 |
return 0; |
| ... | ... |
@@ -144,7 +145,6 @@ static int ac3_sync(AACAC3ParseContext *hdr_info) |
| 144 | 144 |
static av_cold int ac3_parse_init(AVCodecParserContext *s1) |
| 145 | 145 |
{
|
| 146 | 146 |
AACAC3ParseContext *s = s1->priv_data; |
| 147 |
- s->inbuf_ptr = s->inbuf; |
|
| 148 | 147 |
s->header_size = AC3_HEADER_SIZE; |
| 149 | 148 |
s->sync = ac3_sync; |
| 150 | 149 |
return 0; |