* [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet
@ 2022-10-22 21:02 James Almer
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 2/5] avcodec/aac_ac3_parser: don't fill stream info in the sync function James Almer
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: James Almer @ 2022-10-22 21:02 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
No changes since v1.
libavcodec/ac3_parser.c | 19 +++++++++++++++++++
libavcodec/ac3_parser_internal.h | 2 ++
libavcodec/ac3dec.c | 15 ++-------------
3 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 4f154bb7c4..425e1b4742 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -53,6 +53,25 @@ static const uint8_t center_levels[4] = { 4, 5, 6, 5 };
*/
static const uint8_t surround_levels[4] = { 4, 6, 7, 6 };
+int ff_ac3_find_syncword(const uint8_t *buf, int buf_size)
+{
+ int i;
+
+ for (i = 1; i < buf_size; i += 2) {
+ if (buf[i] == 0x77 || buf[i] == 0x0B) {
+ if ((buf[i] ^ buf[i-1]) == (0x77 ^ 0x0B)) {
+ i--;
+ break;
+ } else if ((buf[i] ^ buf[i+1]) == (0x77 ^ 0x0B)) {
+ break;
+ }
+ }
+ }
+ if (i >= buf_size)
+ return AVERROR_INVALIDDATA;
+
+ return i;
+}
int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
{
diff --git a/libavcodec/ac3_parser_internal.h b/libavcodec/ac3_parser_internal.h
index bd4e1bbffb..2ac0e67ec2 100644
--- a/libavcodec/ac3_parser_internal.h
+++ b/libavcodec/ac3_parser_internal.h
@@ -79,4 +79,6 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr);
int avpriv_ac3_parse_header(AC3HeaderInfo **hdr, const uint8_t *buf,
size_t size);
+int ff_ac3_find_syncword(const uint8_t *buf, int buf_size);
+
#endif /* AVCODEC_AC3_PARSER_INTERNAL_H */
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 340f6e1e37..8e40587ff1 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -1508,19 +1508,8 @@ static int ac3_decode_frame(AVCodecContext *avctx, AVFrame *frame,
s->superframe_size = 0;
buf_size = full_buf_size;
- for (i = 1; i < buf_size; i += 2) {
- if (buf[i] == 0x77 || buf[i] == 0x0B) {
- if ((buf[i] ^ buf[i-1]) == (0x77 ^ 0x0B)) {
- i--;
- break;
- } else if ((buf[i] ^ buf[i+1]) == (0x77 ^ 0x0B)) {
- break;
- }
- }
- }
- if (i >= buf_size)
- return AVERROR_INVALIDDATA;
- if (i > 10)
+ i = ff_ac3_find_syncword(buf, buf_size);
+ if (i < 0 || i > 10)
return i;
buf += i;
buf_size -= i;
--
2.37.3
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH 2/5] avcodec/aac_ac3_parser: don't fill stream info in the sync function
2022-10-22 21:02 [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet James Almer
@ 2022-10-22 21:02 ` James Almer
2022-10-23 15:35 ` Michael Niedermayer
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 3/5] avcodec/aac_ac3_parser: don't try to sync when the parser is configured to handle complete frames James Almer
` (4 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: James Almer @ 2022-10-22 21:02 UTC (permalink / raw)
To: ffmpeg-devel
Have it only find frame boundaries. The stream props will then be filled once
we have an assembled frame.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/aac_ac3_parser.c | 63 +++++++++++++++++++++++++++++--------
libavcodec/aac_ac3_parser.h | 12 +------
libavcodec/aac_parser.c | 7 +----
libavcodec/ac3_parser.c | 16 +---------
4 files changed, 53 insertions(+), 45 deletions(-)
diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index b14b1e31f9..6df064e28d 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -26,6 +26,8 @@
#include "libavutil/common.h"
#include "parser.h"
#include "aac_ac3_parser.h"
+#include "ac3_parser_internal.h"
+#include "adts_header.h"
int ff_aac_ac3_parse(AVCodecParserContext *s1,
AVCodecContext *avctx,
@@ -48,7 +50,7 @@ get_next:
len=0;
for(i=s->remaining_size; i<buf_size; i++){
s->state = (s->state<<8) + buf[i];
- if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
+ if((len=s->sync(s->state, &s->need_next_header, &new_frame_start)))
break;
}
if(len<=0){
@@ -79,42 +81,77 @@ get_next:
*poutbuf = buf;
*poutbuf_size = buf_size;
- /* update codec info */
- if(s->codec_id)
- avctx->codec_id = s->codec_id;
-
if (got_frame) {
+ int bit_rate;
+
/* Due to backwards compatible HE-AAC the sample rate, channel count,
and total number of samples found in an AAC ADTS header are not
reliable. Bit rate is still accurate because the total frame
duration in seconds is still correct (as is the number of bits in
the frame). */
if (avctx->codec_id != AV_CODEC_ID_AAC) {
- avctx->sample_rate = s->sample_rate;
+ AC3HeaderInfo hdr, *phrd = &hdr;
+ int offset = ff_ac3_find_syncword(buf, buf_size);
+
+ if (offset < 0)
+ return i;
+
+ buf += offset;
+ buf_size -= offset;
+ while (buf_size > 0) {
+ int ret = avpriv_ac3_parse_header(&phrd, buf, buf_size);
+
+ if (ret < 0 || hdr.frame_size > buf_size)
+ return i;
+
+ if (buf_size > hdr.frame_size) {
+ buf += hdr.frame_size;
+ buf_size -= hdr.frame_size;
+ continue;
+ }
+ break;
+ }
+
+ avctx->sample_rate = hdr.sample_rate;
+
+ if (hdr.bitstream_id > 10)
+ avctx->codec_id = AV_CODEC_ID_EAC3;
+
if (!CONFIG_EAC3_DECODER || avctx->codec_id != AV_CODEC_ID_EAC3) {
av_channel_layout_uninit(&avctx->ch_layout);
- if (s->channel_layout) {
- av_channel_layout_from_mask(&avctx->ch_layout, s->channel_layout);
+ if (hdr.channel_layout) {
+ av_channel_layout_from_mask(&avctx->ch_layout, hdr.channel_layout);
} else {
avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
- avctx->ch_layout.nb_channels = s->channels;
+ avctx->ch_layout.nb_channels = hdr.channels;
}
#if FF_API_OLD_CHANNEL_LAYOUT
FF_DISABLE_DEPRECATION_WARNINGS
avctx->channels = avctx->ch_layout.nb_channels;
- avctx->channel_layout = s->channel_layout;
+ avctx->channel_layout = hdr.channel_layout;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
}
- s1->duration = s->samples;
- avctx->audio_service_type = s->service_type;
+ s1->duration = hdr.num_blocks * 256;
+ avctx->audio_service_type = hdr.bitstream_mode;
+ if (hdr.bitstream_mode == 0x7 && hdr.channels > 1)
+ avctx->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE;
+ bit_rate = hdr.bit_rate;
+ } else {
+ AACADTSHeaderInfo hdr, *phrd = &hdr;
+ int ret = avpriv_adts_header_parse(&phrd, buf, buf_size);
+
+ if (ret < 0)
+ return i;
+
+ bit_rate = hdr.bit_rate;
}
/* Calculate the average bit rate */
s->frame_number++;
if (!CONFIG_EAC3_DECODER || avctx->codec_id != AV_CODEC_ID_EAC3) {
avctx->bit_rate +=
- (s->bit_rate - avctx->bit_rate) / s->frame_number;
+ (bit_rate - avctx->bit_rate) / s->frame_number;
}
}
diff --git a/libavcodec/aac_ac3_parser.h b/libavcodec/aac_ac3_parser.h
index 8b93cbf84f..560bba54f5 100644
--- a/libavcodec/aac_ac3_parser.h
+++ b/libavcodec/aac_ac3_parser.h
@@ -39,24 +39,14 @@ typedef enum {
typedef struct AACAC3ParseContext {
ParseContext pc;
- int frame_size;
int header_size;
- int (*sync)(uint64_t state, struct AACAC3ParseContext *hdr_info,
- int *need_next_header, int *new_frame_start);
-
- int channels;
- int sample_rate;
- int bit_rate;
- int samples;
- uint64_t channel_layout;
- int service_type;
+ int (*sync)(uint64_t state, int *need_next_header, int *new_frame_start);
int remaining_size;
uint64_t state;
int need_next_header;
int frame_number;
- enum AVCodecID codec_id;
} AACAC3ParseContext;
int ff_aac_ac3_parse(AVCodecParserContext *s1,
diff --git a/libavcodec/aac_parser.c b/libavcodec/aac_parser.c
index f3baf7cde3..f295dfccdd 100644
--- a/libavcodec/aac_parser.c
+++ b/libavcodec/aac_parser.c
@@ -27,8 +27,7 @@
#include "get_bits.h"
#include "mpeg4audio.h"
-static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
- int *need_next_header, int *new_frame_start)
+static int aac_sync(uint64_t state, int *need_next_header, int *new_frame_start)
{
GetBitContext bits;
AACADTSHeaderInfo hdr;
@@ -46,10 +45,6 @@ static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
return 0;
*need_next_header = 0;
*new_frame_start = 1;
- hdr_info->sample_rate = hdr.sample_rate;
- hdr_info->channels = ff_mpeg4audio_channels[hdr.chan_config];
- hdr_info->samples = hdr.samples;
- hdr_info->bit_rate = hdr.bit_rate;
return size;
}
diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 425e1b4742..8885e1c72e 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -215,8 +215,7 @@ int av_ac3_parse_header(const uint8_t *buf, size_t size,
return 0;
}
-static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info,
- int *need_next_header, int *new_frame_start)
+static int ac3_sync(uint64_t state, int *need_next_header, int *new_frame_start)
{
int err;
union {
@@ -238,19 +237,6 @@ static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info,
if(err < 0)
return 0;
- hdr_info->sample_rate = hdr.sample_rate;
- hdr_info->bit_rate = hdr.bit_rate;
- hdr_info->channels = hdr.channels;
- hdr_info->channel_layout = hdr.channel_layout;
- hdr_info->samples = hdr.num_blocks * 256;
- hdr_info->service_type = hdr.bitstream_mode;
- if (hdr.bitstream_mode == 0x7 && hdr.channels > 1)
- hdr_info->service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE;
- if(hdr.bitstream_id>10)
- hdr_info->codec_id = AV_CODEC_ID_EAC3;
- else if (hdr_info->codec_id == AV_CODEC_ID_NONE)
- hdr_info->codec_id = AV_CODEC_ID_AC3;
-
*new_frame_start = (hdr.frame_type != EAC3_FRAME_TYPE_DEPENDENT);
*need_next_header = *new_frame_start || (hdr.frame_type != EAC3_FRAME_TYPE_AC3_CONVERT);
return hdr.frame_size;
--
2.37.3
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH 3/5] avcodec/aac_ac3_parser: don't try to sync when the parser is configured to handle complete frames
2022-10-22 21:02 [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet James Almer
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 2/5] avcodec/aac_ac3_parser: don't fill stream info in the sync function James Almer
@ 2022-10-22 21:02 ` James Almer
2022-10-24 21:49 ` Michael Niedermayer
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 4/5] avcodec/aac_ac3_parser: reindent after previous commit James Almer
` (3 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: James Almer @ 2022-10-22 21:02 UTC (permalink / raw)
To: ffmpeg-devel
Should speed up parsing when the frames come from non raw containers.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/aac_ac3_parser.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index 6df064e28d..bfbb55d68e 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -40,6 +40,9 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
int new_frame_start;
int got_frame = 0;
+ if (s1->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+ i = buf_size;
+ } else {
get_next:
i=END_NOT_FOUND;
if(s->remaining_size <= buf_size){
@@ -77,6 +80,7 @@ get_next:
*poutbuf_size = 0;
return buf_size;
}
+ }
*poutbuf = buf;
*poutbuf_size = buf_size;
--
2.37.3
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH 4/5] avcodec/aac_ac3_parser: reindent after previous commit
2022-10-22 21:02 [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet James Almer
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 2/5] avcodec/aac_ac3_parser: don't fill stream info in the sync function James Almer
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 3/5] avcodec/aac_ac3_parser: don't try to sync when the parser is configured to handle complete frames James Almer
@ 2022-10-22 21:02 ` James Almer
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 5/5 v2] avcodec/ac3_parser: improve false positive detection when parsing sync frames James Almer
` (2 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: James Almer @ 2022-10-22 21:02 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/aac_ac3_parser.c | 62 ++++++++++++++++++-------------------
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index bfbb55d68e..e89b12baf9 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -44,42 +44,42 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
i = buf_size;
} else {
get_next:
- i=END_NOT_FOUND;
- if(s->remaining_size <= buf_size){
- if(s->remaining_size && !s->need_next_header){
- i= s->remaining_size;
- s->remaining_size = 0;
- }else{ //we need a header first
- len=0;
- for(i=s->remaining_size; i<buf_size; i++){
- s->state = (s->state<<8) + buf[i];
- if((len=s->sync(s->state, &s->need_next_header, &new_frame_start)))
- break;
- }
- if(len<=0){
- i=END_NOT_FOUND;
- }else{
- got_frame = 1;
- s->state=0;
- i-= s->header_size -1;
- s->remaining_size = len;
- if(!new_frame_start || pc->index+i<=0){
- s->remaining_size += i;
- goto get_next;
+ i=END_NOT_FOUND;
+ if(s->remaining_size <= buf_size){
+ if(s->remaining_size && !s->need_next_header){
+ i= s->remaining_size;
+ s->remaining_size = 0;
+ }else{ //we need a header first
+ len=0;
+ for(i=s->remaining_size; i<buf_size; i++){
+ s->state = (s->state<<8) + buf[i];
+ if((len=s->sync(s->state, &s->need_next_header, &new_frame_start)))
+ break;
}
- else if (i < 0) {
- s->remaining_size += i;
+ if(len<=0){
+ i=END_NOT_FOUND;
+ }else{
+ got_frame = 1;
+ s->state=0;
+ i-= s->header_size -1;
+ s->remaining_size = len;
+ if(!new_frame_start || pc->index+i<=0){
+ s->remaining_size += i;
+ goto get_next;
+ }
+ else if (i < 0) {
+ s->remaining_size += i;
+ }
}
}
}
- }
- if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
- s->remaining_size -= FFMIN(s->remaining_size, buf_size);
- *poutbuf = NULL;
- *poutbuf_size = 0;
- return buf_size;
- }
+ if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
+ s->remaining_size -= FFMIN(s->remaining_size, buf_size);
+ *poutbuf = NULL;
+ *poutbuf_size = 0;
+ return buf_size;
+ }
}
*poutbuf = buf;
--
2.37.3
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH 5/5 v2] avcodec/ac3_parser: improve false positive detection when parsing sync frames
2022-10-22 21:02 [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet James Almer
` (2 preceding siblings ...)
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 4/5] avcodec/aac_ac3_parser: reindent after previous commit James Almer
@ 2022-10-22 21:02 ` James Almer
2022-10-23 23:04 ` [FFmpeg-devel] [PATCH 2/6] avcodec/adts_parsed: allow passing a pre allocated AACADTSHeaderInfo to avpriv_adts_header_parse() James Almer
2022-10-26 12:09 ` [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet James Almer
5 siblings, 0 replies; 12+ messages in thread
From: James Almer @ 2022-10-22 21:02 UTC (permalink / raw)
To: ffmpeg-devel
A two byte sync word is not enough to ensure we got a real syncframe, nor are
all the range checks we do in the first seven bytes. Do therefore an integrity
check for the sync frame in order to prevent the parser from filling avctx with
bogus information.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/aac_ac3_parser.c | 4 ++++
libavcodec/aac_ac3_parser.h | 2 ++
libavcodec/ac3_parser.c | 1 +
3 files changed, 7 insertions(+)
diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index e89b12baf9..2b0ee61b6d 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -113,6 +113,10 @@ get_next:
buf_size -= hdr.frame_size;
continue;
}
+ /* Check for false positives since the syncword is not enough.
+ See section 6.1.2 of A/52. */
+ if (av_crc(s->crc_ctx, 0, buf + 2, hdr.frame_size - 2))
+ return i;
break;
}
diff --git a/libavcodec/aac_ac3_parser.h b/libavcodec/aac_ac3_parser.h
index 560bba54f5..bc16181a19 100644
--- a/libavcodec/aac_ac3_parser.h
+++ b/libavcodec/aac_ac3_parser.h
@@ -24,6 +24,7 @@
#define AVCODEC_AAC_AC3_PARSER_H
#include <stdint.h>
+#include "libavutil/crc.h"
#include "avcodec.h"
#include "parser.h"
@@ -42,6 +43,7 @@ typedef struct AACAC3ParseContext {
int header_size;
int (*sync)(uint64_t state, int *need_next_header, int *new_frame_start);
+ const AVCRC *crc_ctx;
int remaining_size;
uint64_t state;
diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 8885e1c72e..13b8d3b7d8 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -246,6 +246,7 @@ static av_cold int ac3_parse_init(AVCodecParserContext *s1)
{
AACAC3ParseContext *s = s1->priv_data;
s->header_size = AC3_HEADER_SIZE;
+ s->crc_ctx = av_crc_get_table(AV_CRC_16_ANSI);
s->sync = ac3_sync;
return 0;
}
--
2.37.3
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/5] avcodec/aac_ac3_parser: don't fill stream info in the sync function
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 2/5] avcodec/aac_ac3_parser: don't fill stream info in the sync function James Almer
@ 2022-10-23 15:35 ` Michael Niedermayer
2022-10-23 17:34 ` Andreas Rheinhardt
0 siblings, 1 reply; 12+ messages in thread
From: Michael Niedermayer @ 2022-10-23 15:35 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1495 bytes --]
On Sat, Oct 22, 2022 at 06:02:23PM -0300, James Almer wrote:
> Have it only find frame boundaries. The stream props will then be filled once
> we have an assembled frame.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavcodec/aac_ac3_parser.c | 63 +++++++++++++++++++++++++++++--------
> libavcodec/aac_ac3_parser.h | 12 +------
> libavcodec/aac_parser.c | 7 +----
> libavcodec/ac3_parser.c | 16 +---------
> 4 files changed, 53 insertions(+), 45 deletions(-)
i probably forgot something but this breaks:
--- ./tests/ref/fate/adtstoasc_ticket3715 2022-10-22 10:37:36.046518037 +0200
+++ tests/data/fate/adtstoasc_ticket3715 2022-10-23 17:32:17.096459090 +0200
@@ -1,4 +1,4 @@
-29ef0632a8eb5c336bf45a1d5076626e *tests/data/fate/adtstoasc_ticket3715.mov
+4110be924e21846d0e174fac679b062e *tests/data/fate/adtstoasc_ticket3715.mov
33324 tests/data/fate/adtstoasc_ticket3715.mov
#extradata 0: 2, 0x00340022
#tb 0: 1/44100
Test adtstoasc_ticket3715 failed. Look at tests/data/fate/adtstoasc_ticket3715.err for details.
tests/Makefile:306: recipe for target 'fate-adtstoasc_ticket3715' failed
make: *** [fate-adtstoasc_ticket3715] Error 1
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
If you fake or manipulate statistics in a paper in physics you will never
get a job again.
If you fake or manipulate statistics in a paper in medicin you will get
a job for life at the pharma industry.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/5] avcodec/aac_ac3_parser: don't fill stream info in the sync function
2022-10-23 15:35 ` Michael Niedermayer
@ 2022-10-23 17:34 ` Andreas Rheinhardt
2022-10-23 22:59 ` James Almer
0 siblings, 1 reply; 12+ messages in thread
From: Andreas Rheinhardt @ 2022-10-23 17:34 UTC (permalink / raw)
To: ffmpeg-devel
Michael Niedermayer:
> On Sat, Oct 22, 2022 at 06:02:23PM -0300, James Almer wrote:
>> Have it only find frame boundaries. The stream props will then be filled once
>> we have an assembled frame.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> libavcodec/aac_ac3_parser.c | 63 +++++++++++++++++++++++++++++--------
>> libavcodec/aac_ac3_parser.h | 12 +------
>> libavcodec/aac_parser.c | 7 +----
>> libavcodec/ac3_parser.c | 16 +---------
>> 4 files changed, 53 insertions(+), 45 deletions(-)
>
> i probably forgot something but this breaks:
>
> --- ./tests/ref/fate/adtstoasc_ticket3715 2022-10-22 10:37:36.046518037 +0200
> +++ tests/data/fate/adtstoasc_ticket3715 2022-10-23 17:32:17.096459090 +0200
> @@ -1,4 +1,4 @@
> -29ef0632a8eb5c336bf45a1d5076626e *tests/data/fate/adtstoasc_ticket3715.mov
> +4110be924e21846d0e174fac679b062e *tests/data/fate/adtstoasc_ticket3715.mov
> 33324 tests/data/fate/adtstoasc_ticket3715.mov
> #extradata 0: 2, 0x00340022
> #tb 0: 1/44100
> Test adtstoasc_ticket3715 failed. Look at tests/data/fate/adtstoasc_ticket3715.err for details.
> tests/Makefile:306: recipe for target 'fate-adtstoasc_ticket3715' failed
> make: *** [fate-adtstoasc_ticket3715] Error 1
>
> [...]
>
You are not alone: Same thing happened with patchwork.
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/5] avcodec/aac_ac3_parser: don't fill stream info in the sync function
2022-10-23 17:34 ` Andreas Rheinhardt
@ 2022-10-23 22:59 ` James Almer
0 siblings, 0 replies; 12+ messages in thread
From: James Almer @ 2022-10-23 22:59 UTC (permalink / raw)
To: ffmpeg-devel
On 10/23/2022 2:34 PM, Andreas Rheinhardt wrote:
> Michael Niedermayer:
>> On Sat, Oct 22, 2022 at 06:02:23PM -0300, James Almer wrote:
>>> Have it only find frame boundaries. The stream props will then be filled once
>>> we have an assembled frame.
>>>
>>> Signed-off-by: James Almer <jamrial@gmail.com>
>>> ---
>>> libavcodec/aac_ac3_parser.c | 63 +++++++++++++++++++++++++++++--------
>>> libavcodec/aac_ac3_parser.h | 12 +------
>>> libavcodec/aac_parser.c | 7 +----
>>> libavcodec/ac3_parser.c | 16 +---------
>>> 4 files changed, 53 insertions(+), 45 deletions(-)
>>
>> i probably forgot something but this breaks:
>>
>> --- ./tests/ref/fate/adtstoasc_ticket3715 2022-10-22 10:37:36.046518037 +0200
>> +++ tests/data/fate/adtstoasc_ticket3715 2022-10-23 17:32:17.096459090 +0200
>> @@ -1,4 +1,4 @@
>> -29ef0632a8eb5c336bf45a1d5076626e *tests/data/fate/adtstoasc_ticket3715.mov
>> +4110be924e21846d0e174fac679b062e *tests/data/fate/adtstoasc_ticket3715.mov
>> 33324 tests/data/fate/adtstoasc_ticket3715.mov
>> #extradata 0: 2, 0x00340022
>> #tb 0: 1/44100
>> Test adtstoasc_ticket3715 failed. Look at tests/data/fate/adtstoasc_ticket3715.err for details.
>> tests/Makefile:306: recipe for target 'fate-adtstoasc_ticket3715' failed
>> make: *** [fate-adtstoasc_ticket3715] Error 1
>>
>> [...]
>>
>
> You are not alone: Same thing happened with patchwork.
Yes, i noticed and fixed it last night, but didn't send the patch for it
since it was late. Will do it in a bit.
>
> - Andreas
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH 2/6] avcodec/adts_parsed: allow passing a pre allocated AACADTSHeaderInfo to avpriv_adts_header_parse()
2022-10-22 21:02 [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet James Almer
` (3 preceding siblings ...)
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 5/5 v2] avcodec/ac3_parser: improve false positive detection when parsing sync frames James Almer
@ 2022-10-23 23:04 ` James Almer
2022-10-26 12:09 ` [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet James Almer
5 siblings, 0 replies; 12+ messages in thread
From: James Almer @ 2022-10-23 23:04 UTC (permalink / raw)
To: ffmpeg-devel
Code freeing the struct on failure is kept for backwards compatibility, but
should ideally be removed in the next major bump, and the existing lavf user
adapted.
Signed-off-by: James Almer <jamrial@gmail.com>
---
| 2 ++
libavcodec/adts_parser.c | 12 +++++++++---
2 files changed, 11 insertions(+), 3 deletions(-)
--git a/libavcodec/adts_header.c b/libavcodec/adts_header.c
index ff4efafbf7..00fa0a5a99 100644
--- a/libavcodec/adts_header.c
+++ b/libavcodec/adts_header.c
@@ -32,6 +32,8 @@ int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
int size, rdb, ch, sr;
int aot, crc_abs;
+ memset(hdr, 0, sizeof(*hdr));
+
if (get_bits(gbc, 12) != 0xfff)
return AAC_AC3_PARSE_ERROR_SYNC;
diff --git a/libavcodec/adts_parser.c b/libavcodec/adts_parser.c
index 4a1a8fd5f4..f2e155fc99 100644
--- a/libavcodec/adts_parser.c
+++ b/libavcodec/adts_parser.c
@@ -47,24 +47,30 @@ int avpriv_adts_header_parse(AACADTSHeaderInfo **phdr, const uint8_t *buf, size_
{
#if CONFIG_ADTS_HEADER
int ret = 0;
+ int allocated = 0;
GetBitContext gb;
if (!phdr || !buf || size < AV_AAC_ADTS_HEADER_SIZE)
return AVERROR_INVALIDDATA;
- *phdr = av_mallocz(sizeof(AACADTSHeaderInfo));
+ if (!*phdr) {
+ allocated = 1;
+ *phdr = av_mallocz(sizeof(AACADTSHeaderInfo));
+ }
if (!*phdr)
return AVERROR(ENOMEM);
ret = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
if (ret < 0) {
- av_freep(phdr);
+ if (allocated)
+ av_freep(phdr);
return ret;
}
ret = ff_adts_header_parse(&gb, *phdr);
if (ret < 0) {
- av_freep(phdr);
+ if (allocated)
+ av_freep(phdr);
return ret;
}
--
2.37.3
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH 3/5] avcodec/aac_ac3_parser: don't try to sync when the parser is configured to handle complete frames
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 3/5] avcodec/aac_ac3_parser: don't try to sync when the parser is configured to handle complete frames James Almer
@ 2022-10-24 21:49 ` Michael Niedermayer
2022-10-24 22:26 ` [FFmpeg-devel] [PATCH 4/6 v2] " James Almer
0 siblings, 1 reply; 12+ messages in thread
From: Michael Niedermayer @ 2022-10-24 21:49 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 644 bytes --]
On Sat, Oct 22, 2022 at 06:02:24PM -0300, James Almer wrote:
> Should speed up parsing when the frames come from non raw containers.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavcodec/aac_ac3_parser.c | 4 ++++
> 1 file changed, 4 insertions(+)
produces bad timestamps in
./ffmpeg -i ~/tickets/2508/S09E01.\ Smallville\ -\ Savior\ -\ no\ audio\ sample.mkv -t 1 -bitexact -vn -f framecrc -
link to sample is in ticket
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [FFmpeg-devel] [PATCH 4/6 v2] avcodec/aac_ac3_parser: don't try to sync when the parser is configured to handle complete frames
2022-10-24 21:49 ` Michael Niedermayer
@ 2022-10-24 22:26 ` James Almer
0 siblings, 0 replies; 12+ messages in thread
From: James Almer @ 2022-10-24 22:26 UTC (permalink / raw)
To: ffmpeg-devel
Should speed up parsing when the frames come from non raw containers.
Signed-off-by: James Almer <jamrial@gmail.com>
---
The got_frame variable can probably be removed. ff_combine_frame() should return
success only if the end of a frame was found. Will look at that later.
libavcodec/aac_ac3_parser.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c
index 6df064e28d..b2cb79801e 100644
--- a/libavcodec/aac_ac3_parser.c
+++ b/libavcodec/aac_ac3_parser.c
@@ -40,6 +40,10 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
int new_frame_start;
int got_frame = 0;
+ if (s1->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+ i = buf_size;
+ got_frame = 1;
+ } else {
get_next:
i=END_NOT_FOUND;
if(s->remaining_size <= buf_size){
@@ -77,6 +81,7 @@ get_next:
*poutbuf_size = 0;
return buf_size;
}
+ }
*poutbuf = buf;
*poutbuf_size = buf_size;
--
2.38.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet
2022-10-22 21:02 [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet James Almer
` (4 preceding siblings ...)
2022-10-23 23:04 ` [FFmpeg-devel] [PATCH 2/6] avcodec/adts_parsed: allow passing a pre allocated AACADTSHeaderInfo to avpriv_adts_header_parse() James Almer
@ 2022-10-26 12:09 ` James Almer
5 siblings, 0 replies; 12+ messages in thread
From: James Almer @ 2022-10-26 12:09 UTC (permalink / raw)
To: ffmpeg-devel
On 10/22/2022 6:02 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> No changes since v1.
>
> libavcodec/ac3_parser.c | 19 +++++++++++++++++++
> libavcodec/ac3_parser_internal.h | 2 ++
> libavcodec/ac3dec.c | 15 ++-------------
> 3 files changed, 23 insertions(+), 13 deletions(-)
>
> diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
> index 4f154bb7c4..425e1b4742 100644
> --- a/libavcodec/ac3_parser.c
> +++ b/libavcodec/ac3_parser.c
> @@ -53,6 +53,25 @@ static const uint8_t center_levels[4] = { 4, 5, 6, 5 };
> */
> static const uint8_t surround_levels[4] = { 4, 6, 7, 6 };
>
> +int ff_ac3_find_syncword(const uint8_t *buf, int buf_size)
> +{
> + int i;
> +
> + for (i = 1; i < buf_size; i += 2) {
> + if (buf[i] == 0x77 || buf[i] == 0x0B) {
> + if ((buf[i] ^ buf[i-1]) == (0x77 ^ 0x0B)) {
> + i--;
> + break;
> + } else if ((buf[i] ^ buf[i+1]) == (0x77 ^ 0x0B)) {
> + break;
> + }
> + }
> + }
> + if (i >= buf_size)
> + return AVERROR_INVALIDDATA;
> +
> + return i;
> +}
>
> int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
> {
> diff --git a/libavcodec/ac3_parser_internal.h b/libavcodec/ac3_parser_internal.h
> index bd4e1bbffb..2ac0e67ec2 100644
> --- a/libavcodec/ac3_parser_internal.h
> +++ b/libavcodec/ac3_parser_internal.h
> @@ -79,4 +79,6 @@ int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr);
> int avpriv_ac3_parse_header(AC3HeaderInfo **hdr, const uint8_t *buf,
> size_t size);
>
> +int ff_ac3_find_syncword(const uint8_t *buf, int buf_size);
> +
> #endif /* AVCODEC_AC3_PARSER_INTERNAL_H */
> diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
> index 340f6e1e37..8e40587ff1 100644
> --- a/libavcodec/ac3dec.c
> +++ b/libavcodec/ac3dec.c
> @@ -1508,19 +1508,8 @@ static int ac3_decode_frame(AVCodecContext *avctx, AVFrame *frame,
> s->superframe_size = 0;
>
> buf_size = full_buf_size;
> - for (i = 1; i < buf_size; i += 2) {
> - if (buf[i] == 0x77 || buf[i] == 0x0B) {
> - if ((buf[i] ^ buf[i-1]) == (0x77 ^ 0x0B)) {
> - i--;
> - break;
> - } else if ((buf[i] ^ buf[i+1]) == (0x77 ^ 0x0B)) {
> - break;
> - }
> - }
> - }
> - if (i >= buf_size)
> - return AVERROR_INVALIDDATA;
> - if (i > 10)
> + i = ff_ac3_find_syncword(buf, buf_size);
> + if (i < 0 || i > 10)
> return i;
> buf += i;
> buf_size -= i;
Will apply set.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2022-10-26 12:09 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-22 21:02 [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet James Almer
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 2/5] avcodec/aac_ac3_parser: don't fill stream info in the sync function James Almer
2022-10-23 15:35 ` Michael Niedermayer
2022-10-23 17:34 ` Andreas Rheinhardt
2022-10-23 22:59 ` James Almer
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 3/5] avcodec/aac_ac3_parser: don't try to sync when the parser is configured to handle complete frames James Almer
2022-10-24 21:49 ` Michael Niedermayer
2022-10-24 22:26 ` [FFmpeg-devel] [PATCH 4/6 v2] " James Almer
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 4/5] avcodec/aac_ac3_parser: reindent after previous commit James Almer
2022-10-22 21:02 ` [FFmpeg-devel] [PATCH 5/5 v2] avcodec/ac3_parser: improve false positive detection when parsing sync frames James Almer
2022-10-23 23:04 ` [FFmpeg-devel] [PATCH 2/6] avcodec/adts_parsed: allow passing a pre allocated AACADTSHeaderInfo to avpriv_adts_header_parse() James Almer
2022-10-26 12:09 ` [FFmpeg-devel] [PATCH 1/5 v2] avcodec/ac3dec: split off code discarding garbage at the beginning of a packet James Almer
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git