On sobota, 22 marca 2008, Michael Niedermayer wrote:
> This contains several unrelated changes.
>
> First the the addition of AACAC3HeaderInfo, IMHO you should simply pass a
> pointer to AACAC3ParseContext into sync(). This should be in a seperate
> patch and can likely hit ffmpeg svn quickly.
As I wrote, this is new version of ffmpeg.patch from soc/eac3 repository,
because without eac3 this makes no sense. From this file derived other
updates (e.g. bap_tab is sometimes ff_ac3_bap_tab and sometimes
ff_eac3_hebap_tab, and other changes concerning eac3). But maybe is better to
send to svn ffmpeg this patch and then start to update the rest, so i enclose
separate patch.
--
Bartlomiej Wolowiec
Index: libavcodec/aac_ac3_parser.c
===================================================================
--- libavcodec/aac_ac3_parser.c (wersja 12549)
+++ libavcodec/aac_ac3_parser.c (kopia robocza)
@@ -23,6 +23,7 @@
#include "parser.h"
#include "aac_ac3_parser.h"
+// TODO check s->inbuf_tab size
int ff_aac_ac3_parse(AVCodecParserContext *s1,
AVCodecContext *avctx,
const uint8_t **poutbuf, int *poutbuf_size,
@@ -30,12 +31,19 @@
{
AACAC3ParseContext *s = s1->priv_data;
const uint8_t *buf_ptr;
- int len, sample_rate, bit_rate, channels, samples;
+ int len;
*poutbuf = NULL;
*poutbuf_size = 0;
buf_ptr = buf;
+
+ if(s->inbuf_ptr < s->inbuf) {
+ //after sending package of data in the end there was one new header
+ memcpy(s->inbuf_tab, s->inbuf, s->header_size);
+ s->inbuf = s->inbuf_tab;
+ s->inbuf_ptr = s->inbuf_tab + s->header_size;
+ }
while (buf_size > 0) {
int size_needed= s->frame_size ? s->frame_size : s->header_size;
len = s->inbuf_ptr - s->inbuf;
@@ -50,37 +58,46 @@
if (s->frame_size == 0) {
if ((s->inbuf_ptr - s->inbuf) == s->header_size) {
- len = s->sync(s->inbuf, &channels, &sample_rate, &bit_rate,
- &samples);
+ len = s->sync(s);
if (len == 0) {
/* no sync found : move by one byte (inefficient, but simple!) */
memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);
s->inbuf_ptr--;
} else {
- s->frame_size = len;
+ if(!s->stream_type) {
+ if(s->inbuf != s->inbuf_tab) {
+ *poutbuf = s->inbuf_tab;
+ *poutbuf_size = s->inbuf - s->inbuf_tab;
+ s->inbuf_ptr = s->inbuf_tab;
+ s->frame_size = 0;
+ break;
+ }
/* update codec info */
- avctx->sample_rate = sample_rate;
+ avctx->sample_rate = s->sample_rate;
/* allow downmixing to stereo (or mono for AC3) */
if(avctx->request_channels > 0 &&
- avctx->request_channels < channels &&
+ avctx->request_channels < s->channels &&
(avctx->request_channels <= 2 ||
(avctx->request_channels == 1 &&
avctx->codec_id == CODEC_ID_AC3))) {
avctx->channels = avctx->request_channels;
} else {
- avctx->channels = channels;
+ avctx->channels = s->channels;
}
- avctx->bit_rate = bit_rate;
- avctx->frame_size = samples;
+ avctx->bit_rate = s->bit_rate;
+ avctx->frame_size = s->samples;
+ } else {
+ //TODO update bit_rate
+ avctx->frame_size += s->samples;
+ }
+ s->frame_size = len;
}
}
} else {
if(s->inbuf_ptr - s->inbuf == s->frame_size){
- *poutbuf = s->inbuf;
- *poutbuf_size = s->frame_size;
+ s->inbuf += s->frame_size;
s->inbuf_ptr = s->inbuf;
s->frame_size = 0;
- break;
}
}
}
Index: libavcodec/aac_ac3_parser.h
===================================================================
--- libavcodec/aac_ac3_parser.h (wersja 12549)
+++ libavcodec/aac_ac3_parser.h (kopia robocza)
@@ -27,12 +27,18 @@
#include "avcodec.h"
typedef struct AACAC3ParseContext {
- uint8_t *inbuf_ptr;
+ uint8_t *inbuf_ptr; ///< not read part of frame
+ uint8_t *inbuf; ///< beginning of current frame
int frame_size;
int header_size;
- int (*sync)(const uint8_t *buf, int *channels, int *sample_rate,
- int *bit_rate, int *samples);
- uint8_t inbuf[8192]; /* input buffer */
+ int (*sync)(struct AACAC3ParseContext *hdr_info);
+ uint8_t inbuf_tab[8192]; /* input buffer */
+
+ int channels;
+ int sample_rate;
+ int bit_rate;
+ int samples;
+ int stream_type; ///< for eac3
} AACAC3ParseContext;
int ff_aac_ac3_parse(AVCodecParserContext *s1,
Index: libavcodec/aac_parser.c
===================================================================
--- libavcodec/aac_parser.c (wersja 12549)
+++ libavcodec/aac_parser.c (kopia robocza)
@@ -38,13 +38,12 @@
};
-static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate,
- int *bit_rate, int *samples)
+static int aac_sync(AACAC3ParseContext *hdr_info)
{
GetBitContext bits;
int size, rdb, ch, sr;
- init_get_bits(&bits, buf, AAC_HEADER_SIZE * 8);
+ init_get_bits(&bits, hdr_info->inbuf, AAC_HEADER_SIZE * 8);
if(get_bits(&bits, 12) != 0xfff)
return 0;
@@ -73,10 +72,10 @@
skip_bits(&bits, 11); /* adts_buffer_fullness */
rdb = get_bits(&bits, 2); /* number_of_raw_data_blocks_in_frame */
- *channels = aac_channels[ch];
- *sample_rate = aac_sample_rates[sr];
- *samples = (rdb + 1) * 1024;
- *bit_rate = size * 8 * *sample_rate / *samples;
+ hdr_info->channels = aac_channels[ch];
+ hdr_info->sample_rate = aac_sample_rates[sr];
+ hdr_info->samples = (rdb + 1) * 1024;
+ hdr_info->bit_rate = size * 8 * hdr_info->sample_rate / hdr_info->samples;
return size;
}
@@ -84,6 +83,8 @@
static av_cold int aac_parse_init(AVCodecParserContext *s1)
{
AACAC3ParseContext *s = s1->priv_data;
+ s->inbuf = s->inbuf_tab;
+ s->stream_type = 0;
s->inbuf_ptr = s->inbuf;
s->header_size = AAC_HEADER_SIZE;
s->sync = aac_sync;
Index: libavcodec/ac3_parser.c
===================================================================
--- libavcodec/ac3_parser.c (wersja 12549)
+++ libavcodec/ac3_parser.c (kopia robocza)
@@ -84,10 +84,11 @@
hdr->bit_rate = (ff_ac3_bitrate_tab[frame_size_code>>1] * 1000) >> hdr->sr_shift;
hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on;
hdr->frame_size = ff_ac3_frame_size_tab[frame_size_code][hdr->sr_code] * 2;
+ hdr->stream_type = 0;
} else {
/* Enhanced AC-3 */
hdr->crc1 = 0;
- skip_bits(&gbc, 2); // skip stream type
+ hdr->stream_type = get_bits(&gbc, 2);
skip_bits(&gbc, 3); // skip substream id
hdr->frame_size = (get_bits(&gbc, 11) + 1) << 1;
@@ -119,27 +120,29 @@
return 0;
}
-static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
- int *bit_rate, int *samples)
+static int ac3_sync(AACAC3ParseContext *hdr_info)
{
int err;
AC3HeaderInfo hdr;
- err = ff_ac3_parse_header(buf, &hdr);
+ err = ff_ac3_parse_header(hdr_info->inbuf, &hdr);
if(err < 0)
return 0;
- *sample_rate = hdr.sample_rate;
- *bit_rate = hdr.bit_rate;
- *channels = hdr.channels;
- *samples = AC3_FRAME_SIZE;
+ hdr_info->sample_rate = hdr.sample_rate;
+ hdr_info->bit_rate = hdr.bit_rate;
+ hdr_info->channels = hdr.channels;
+ //FIXME: hdr_info->samples = hdr.num_blocks * 256;
+ hdr_info->samples = AC3_FRAME_SIZE;
+ hdr_info->stream_type = hdr.stream_type;
return hdr.frame_size;
}
static av_cold int ac3_parse_init(AVCodecParserContext *s1)
{
AACAC3ParseContext *s = s1->priv_data;
+ s->inbuf = s->inbuf_tab;
s->inbuf_ptr = s->inbuf;
s->header_size = AC3_HEADER_SIZE;
s->sync = ac3_sync;
Index: libavcodec/ac3.h
===================================================================
--- libavcodec/ac3.h (wersja 12549)
+++ libavcodec/ac3.h (kopia robocza)
@@ -84,6 +84,7 @@
uint8_t bitstream_id;
uint8_t channel_mode;
uint8_t lfe_on;
+ uint8_t stream_type;
/** @} */
/** @defgroup derived Derived values
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc