Re: [libav-devel] [PATCH] Use deinterleavers for demangling audio packets in RealMedia.

2011-08-29 Thread Ronald S. Bultje
Hi,

On Aug 29, 2011 12:37 AM, "Kostya"  wrote:
>
> On Mon, Aug 29, 2011 at 07:59:14AM +0200, Vladimir Pantelic wrote:
> > Kostya Shishkov wrote:
> > >Unlike other containers RealMedia stores its audio packets in scrambled
form,
> >
> > not only RealMedia, MKV does the same for some audio codecs, no?
>
> Yes, but it's up to MKV demuxer to descramble audio packets there (and it
does
> so), probably it specifies EBXSLT to transform that data in EB(X)ML.

No, it uses rmdec functions.

Ronald
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] Use deinterleavers for demangling audio packets in RealMedia.

2011-08-29 Thread Kostya
On Mon, Aug 29, 2011 at 07:59:14AM +0200, Vladimir Pantelic wrote:
> Kostya Shishkov wrote:
> >Unlike other containers RealMedia stores its audio packets in scrambled form,
> 
> not only RealMedia, MKV does the same for some audio codecs, no?

Yes, but it's up to MKV demuxer to descramble audio packets there (and it does
so), probably it specifies EBXSLT to transform that data in EB(X)ML.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] Use deinterleavers for demangling audio packets in RealMedia.

2011-08-28 Thread Vladimir Pantelic

Kostya Shishkov wrote:

Unlike other containers RealMedia stores its audio packets in scrambled form,


not only RealMedia, MKV does the same for some audio codecs, no?


with interleaver ID preceeding audio codec ID. Currently deinterleaving
decision is tied to the codec while it's possible to have non-default
deinterleaver with audio codec (like Int0 deinterleaver instead of specific
one for Sipro).

This also fixes playback of
http://www.cccp-project.net/beta/test_files/mega_weird_audio/Mega_Weird_Audio_2ch_RA5_SIPR.ra
---
  libavformat/rmdec.c |   46 ++
  1 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 7cf5720..9c0a3ff 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -26,6 +26,13 @@
  #include "riff.h"
  #include "rm.h"

+#define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///<  interleaving for 
Cooker/Atrac
+#define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///<  no interleaving needed
+#define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///<  interleaving for 28.8
+#define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///<  interleaving for Sipro
+#define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///<  VBR case for AAC
+#define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///<  VBR case for AAC
+
  struct RMStream {
  AVPacket pkt;  ///<  place to store merged video frame / reordered 
audio data
  int videobufsize;  ///<  current assembled frame size
@@ -39,6 +46,7 @@ struct RMStream {
  int sub_packet_size, sub_packet_h, coded_framesize; ///<  Descrambling 
parameters from container
  int audio_framesize; /// Audio frame size from container
  int sub_packet_lengths[16]; /// Length of each subpacket
+int32_t deint_id;  ///<  deinterleaver used in audio stream
  };

  typedef struct {
@@ -147,6 +155,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, 
AVIOContext *pb,
  st->codec->channels = 1;
  st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  st->codec->codec_id = CODEC_ID_RA_144;
+ast->deint_id = DEINT_ID_INT0;
  } else {
  int flavor, sub_packet_h, coded_framesize, sub_packet_size;
  int codecdata_length;
@@ -172,17 +181,31 @@ static int rm_read_audio_stream_info(AVFormatContext *s, 
AVIOContext *pb,
  avio_rb32(pb);
  st->codec->channels = avio_rb16(pb);
  if (version == 5) {
-avio_rb32(pb);
+ast->deint_id = avio_rl32(pb);
  avio_read(pb, buf, 4);
  buf[4] = 0;
  } else {
  get_str8(pb, buf, sizeof(buf)); /* desc */
+ast->deint_id = AV_RL32(buf);
  get_str8(pb, buf, sizeof(buf)); /* desc */
  }
  st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  st->codec->codec_tag  = AV_RL32(buf);
  st->codec->codec_id   = ff_codec_get_id(ff_rm_codec_tags,
  st->codec->codec_tag);
+
+switch (ast->deint_id) {
+case DEINT_ID_GENR:
+case DEINT_ID_INT0:
+case DEINT_ID_INT4:
+case DEINT_ID_SIPR:
+case DEINT_ID_VBRS:
+case DEINT_ID_VBRF:
+break;
+default:
+av_log(NULL,0,"Unknown interleaver %X\n", ast->deint_id);
+return -1;
+}
  switch (st->codec->codec_id) {
  case CODEC_ID_AC3:
  st->need_parsing = AVSTREAM_PARSE_FULL;
@@ -704,10 +727,9 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
  if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq,×tamp))
  return -1; //got partial frame
  } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
-if ((st->codec->codec_id == CODEC_ID_RA_288) ||
-(st->codec->codec_id == CODEC_ID_COOK) ||
-(st->codec->codec_id == CODEC_ID_ATRAC3) ||
-(st->codec->codec_id == CODEC_ID_SIPR)) {
+if ((ast->deint_id == DEINT_ID_GENR) ||
+(ast->deint_id == DEINT_ID_INT4) ||
+(ast->deint_id == DEINT_ID_SIPR)) {
  int x;
  int sps = ast->sub_packet_size;
  int cfs = ast->coded_framesize;
@@ -720,30 +742,30 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
  if (!y)
  ast->audiotimestamp = timestamp;

-switch(st->codec->codec_id) {
-case CODEC_ID_RA_288:
+switch(ast->deint_id) {
+case DEINT_ID_INT4:
  for (x = 0; x<  h/2; x++)
  avio_read(pb, ast->pkt.data+x*2*w+y*cfs, cfs);
  break;
-case CODEC_ID_ATRAC3:
-case CODEC_ID_COOK:
+case DEINT_ID_GENR:
  for (x = 0; x<  w/sps; x++)
  avio_read(pb, 
ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
  break;
-case CODE

Re: [libav-devel] [PATCH] Use deinterleavers for demangling audio packets in RealMedia.

2011-08-27 Thread Anton Khirnov

On Sat, 27 Aug 2011 14:57:33 +0200, Kostya  wrote:
Non-text part: multipart/mixed
> On Sat, Aug 27, 2011 at 01:39:03PM +0200, Anton Khirnov wrote:
> > 
> > On Sat, 27 Aug 2011 12:15:28 +0200, Kostya Shishkov 
> >  wrote:
> > > Unlike other containers RealMedia stores its audio packets in scrambled 
> > > form,
> > > with interleaver ID preceeding audio codec ID. Currently deinterleaving
> > > decision is tied to the codec while it's possible to have non-default
> > > deinterleaver with audio codec (like Int0 deinterleaver instead of 
> > > specific
> > > one for Sipro).
> > > 
> > > This also fixes playback of
> > > http://www.cccp-project.net/beta/test_files/mega_weird_audio/Mega_Weird_Audio_2ch_RA5_SIPR.ra
> > > ---
> > >  libavformat/rmdec.c |   46 ++
> > >  1 files changed, 34 insertions(+), 12 deletions(-)
> > > 
> > 
> > Looks sane, except for some cosmetics
> 
> Sorry, it's one of the founding files, existing before Diego and resisting
> his attempts to make code prettier.
>  
> > > diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
> > > index 7cf5720..9c0a3ff 100644
> > > --- a/libavformat/rmdec.c
> > > +++ b/libavformat/rmdec.c
> > > @@ -26,6 +26,13 @@
> > >  #include "riff.h"
> > >  #include "rm.h"
> > >  
> > > +#define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///< interleaving for 
> > > Cooker/Atrac
> > > +#define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///< no interleaving 
> > > needed
> > > +#define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///< interleaving for 
> > > 28.8
> > > +#define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///< interleaving for 
> > > Sipro
> > > +#define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///< VBR case for AAC
> > > +#define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///< VBR case for AAC
> > > +
> > >  struct RMStream {
> > >  AVPacket pkt;  ///< place to store merged video frame / 
> > > reordered audio data
> > >  int videobufsize;  ///< current assembled frame size
> > > @@ -39,6 +46,7 @@ struct RMStream {
> > >  int sub_packet_size, sub_packet_h, coded_framesize; ///< 
> > > Descrambling parameters from container
> > >  int audio_framesize; /// Audio frame size from container
> > >  int sub_packet_lengths[16]; /// Length of each subpacket
> > > +int32_t deint_id;  ///< deinterleaver used in audio stream
> > >  };
> > >  
> > >  typedef struct {
> > > @@ -147,6 +155,7 @@ static int rm_read_audio_stream_info(AVFormatContext 
> > > *s, AVIOContext *pb,
> > >  st->codec->channels = 1;
> > >  st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
> > >  st->codec->codec_id = CODEC_ID_RA_144;
> > > +ast->deint_id = DEINT_ID_INT0;
> > >  } else {
> > >  int flavor, sub_packet_h, coded_framesize, sub_packet_size;
> > >  int codecdata_length;
> > > @@ -172,17 +181,31 @@ static int 
> > > rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
> > >  avio_rb32(pb);
> > >  st->codec->channels = avio_rb16(pb);
> > >  if (version == 5) {
> > > -avio_rb32(pb);
> > > +ast->deint_id = avio_rl32(pb);
> > >  avio_read(pb, buf, 4);
> > >  buf[4] = 0;
> > >  } else {
> > >  get_str8(pb, buf, sizeof(buf)); /* desc */
> > > +ast->deint_id = AV_RL32(buf);
> > >  get_str8(pb, buf, sizeof(buf)); /* desc */
> > >  }
> > >  st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
> > >  st->codec->codec_tag  = AV_RL32(buf);
> > >  st->codec->codec_id   = ff_codec_get_id(ff_rm_codec_tags,
> > >  st->codec->codec_tag);
> > > +
> > > +switch (ast->deint_id) {
> > > +case DEINT_ID_GENR:
> > > +case DEINT_ID_INT0:
> > > +case DEINT_ID_INT4:
> > > +case DEINT_ID_SIPR:
> > > +case DEINT_ID_VBRS:
> > > +case DEINT_ID_VBRF:
> > > +break;
> > > +default:
> > > +av_log(NULL,0,"Unknown interleaver %X\n", ast->deint_id);
> > > +return -1;
> > 
> > AVERROR_INVALIDDATA please
> 
> here you are
> 
> > > +}
> > >  switch (st->codec->codec_id) {
> > >  case CODEC_ID_AC3:
> > >  st->need_parsing = AVSTREAM_PARSE_FULL;
> > > @@ -704,10 +727,9 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext 
> > > *pb,
> > >  if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, 
> > > ×tamp))
> > >  return -1; //got partial frame
> > >  } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
> > > -if ((st->codec->codec_id == CODEC_ID_RA_288) ||
> > > -(st->codec->codec_id == CODEC_ID_COOK) ||
> > > -(st->codec->codec_id == CODEC_ID_ATRAC3) ||
> > > -(st->codec->codec_id == CODEC_ID_SIPR)) {
> > > +if ((ast->deint_id == DEINT_ID_GENR) ||
> > > +(ast->deint_id == DEINT_ID_INT4) ||
> > > +

Re: [libav-devel] [PATCH] Use deinterleavers for demangling audio packets in RealMedia.

2011-08-27 Thread Kostya
On Sat, Aug 27, 2011 at 01:39:03PM +0200, Anton Khirnov wrote:
> 
> On Sat, 27 Aug 2011 12:15:28 +0200, Kostya Shishkov 
>  wrote:
> > Unlike other containers RealMedia stores its audio packets in scrambled 
> > form,
> > with interleaver ID preceeding audio codec ID. Currently deinterleaving
> > decision is tied to the codec while it's possible to have non-default
> > deinterleaver with audio codec (like Int0 deinterleaver instead of specific
> > one for Sipro).
> > 
> > This also fixes playback of
> > http://www.cccp-project.net/beta/test_files/mega_weird_audio/Mega_Weird_Audio_2ch_RA5_SIPR.ra
> > ---
> >  libavformat/rmdec.c |   46 ++
> >  1 files changed, 34 insertions(+), 12 deletions(-)
> > 
> 
> Looks sane, except for some cosmetics

Sorry, it's one of the founding files, existing before Diego and resisting
his attempts to make code prettier.
 
> > diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
> > index 7cf5720..9c0a3ff 100644
> > --- a/libavformat/rmdec.c
> > +++ b/libavformat/rmdec.c
> > @@ -26,6 +26,13 @@
> >  #include "riff.h"
> >  #include "rm.h"
> >  
> > +#define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///< interleaving for 
> > Cooker/Atrac
> > +#define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///< no interleaving needed
> > +#define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///< interleaving for 28.8
> > +#define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///< interleaving for Sipro
> > +#define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///< VBR case for AAC
> > +#define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///< VBR case for AAC
> > +
> >  struct RMStream {
> >  AVPacket pkt;  ///< place to store merged video frame / reordered 
> > audio data
> >  int videobufsize;  ///< current assembled frame size
> > @@ -39,6 +46,7 @@ struct RMStream {
> >  int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling 
> > parameters from container
> >  int audio_framesize; /// Audio frame size from container
> >  int sub_packet_lengths[16]; /// Length of each subpacket
> > +int32_t deint_id;  ///< deinterleaver used in audio stream
> >  };
> >  
> >  typedef struct {
> > @@ -147,6 +155,7 @@ static int rm_read_audio_stream_info(AVFormatContext 
> > *s, AVIOContext *pb,
> >  st->codec->channels = 1;
> >  st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
> >  st->codec->codec_id = CODEC_ID_RA_144;
> > +ast->deint_id = DEINT_ID_INT0;
> >  } else {
> >  int flavor, sub_packet_h, coded_framesize, sub_packet_size;
> >  int codecdata_length;
> > @@ -172,17 +181,31 @@ static int rm_read_audio_stream_info(AVFormatContext 
> > *s, AVIOContext *pb,
> >  avio_rb32(pb);
> >  st->codec->channels = avio_rb16(pb);
> >  if (version == 5) {
> > -avio_rb32(pb);
> > +ast->deint_id = avio_rl32(pb);
> >  avio_read(pb, buf, 4);
> >  buf[4] = 0;
> >  } else {
> >  get_str8(pb, buf, sizeof(buf)); /* desc */
> > +ast->deint_id = AV_RL32(buf);
> >  get_str8(pb, buf, sizeof(buf)); /* desc */
> >  }
> >  st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
> >  st->codec->codec_tag  = AV_RL32(buf);
> >  st->codec->codec_id   = ff_codec_get_id(ff_rm_codec_tags,
> >  st->codec->codec_tag);
> > +
> > +switch (ast->deint_id) {
> > +case DEINT_ID_GENR:
> > +case DEINT_ID_INT0:
> > +case DEINT_ID_INT4:
> > +case DEINT_ID_SIPR:
> > +case DEINT_ID_VBRS:
> > +case DEINT_ID_VBRF:
> > +break;
> > +default:
> > +av_log(NULL,0,"Unknown interleaver %X\n", ast->deint_id);
> > +return -1;
> 
> AVERROR_INVALIDDATA please

here you are

> > +}
> >  switch (st->codec->codec_id) {
> >  case CODEC_ID_AC3:
> >  st->need_parsing = AVSTREAM_PARSE_FULL;
> > @@ -704,10 +727,9 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext 
> > *pb,
> >  if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, 
> > ×tamp))
> >  return -1; //got partial frame
> >  } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
> > -if ((st->codec->codec_id == CODEC_ID_RA_288) ||
> > -(st->codec->codec_id == CODEC_ID_COOK) ||
> > -(st->codec->codec_id == CODEC_ID_ATRAC3) ||
> > -(st->codec->codec_id == CODEC_ID_SIPR)) {
> > +if ((ast->deint_id == DEINT_ID_GENR) ||
> > +(ast->deint_id == DEINT_ID_INT4) ||
> > +(ast->deint_id == DEINT_ID_SIPR)) {
> >  int x;
> >  int sps = ast->sub_packet_size;
> >  int cfs = ast->coded_framesize;
> > @@ -720,30 +742,30 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext 
> > *pb,
> >  if (!y)
> >  ast->audiotimestamp = timestamp;
> > 

Re: [libav-devel] [PATCH] Use deinterleavers for demangling audio packets in RealMedia.

2011-08-27 Thread Anton Khirnov

On Sat, 27 Aug 2011 12:15:28 +0200, Kostya Shishkov  
wrote:
> Unlike other containers RealMedia stores its audio packets in scrambled form,
> with interleaver ID preceeding audio codec ID. Currently deinterleaving
> decision is tied to the codec while it's possible to have non-default
> deinterleaver with audio codec (like Int0 deinterleaver instead of specific
> one for Sipro).
> 
> This also fixes playback of
> http://www.cccp-project.net/beta/test_files/mega_weird_audio/Mega_Weird_Audio_2ch_RA5_SIPR.ra
> ---
>  libavformat/rmdec.c |   46 ++
>  1 files changed, 34 insertions(+), 12 deletions(-)
> 

Looks sane, except for some cosmetics

> diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
> index 7cf5720..9c0a3ff 100644
> --- a/libavformat/rmdec.c
> +++ b/libavformat/rmdec.c
> @@ -26,6 +26,13 @@
>  #include "riff.h"
>  #include "rm.h"
>  
> +#define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///< interleaving for 
> Cooker/Atrac
> +#define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///< no interleaving needed
> +#define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///< interleaving for 28.8
> +#define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///< interleaving for Sipro
> +#define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///< VBR case for AAC
> +#define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///< VBR case for AAC
> +
>  struct RMStream {
>  AVPacket pkt;  ///< place to store merged video frame / reordered 
> audio data
>  int videobufsize;  ///< current assembled frame size
> @@ -39,6 +46,7 @@ struct RMStream {
>  int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling 
> parameters from container
>  int audio_framesize; /// Audio frame size from container
>  int sub_packet_lengths[16]; /// Length of each subpacket
> +int32_t deint_id;  ///< deinterleaver used in audio stream
>  };
>  
>  typedef struct {
> @@ -147,6 +155,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, 
> AVIOContext *pb,
>  st->codec->channels = 1;
>  st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
>  st->codec->codec_id = CODEC_ID_RA_144;
> +ast->deint_id = DEINT_ID_INT0;
>  } else {
>  int flavor, sub_packet_h, coded_framesize, sub_packet_size;
>  int codecdata_length;
> @@ -172,17 +181,31 @@ static int rm_read_audio_stream_info(AVFormatContext 
> *s, AVIOContext *pb,
>  avio_rb32(pb);
>  st->codec->channels = avio_rb16(pb);
>  if (version == 5) {
> -avio_rb32(pb);
> +ast->deint_id = avio_rl32(pb);
>  avio_read(pb, buf, 4);
>  buf[4] = 0;
>  } else {
>  get_str8(pb, buf, sizeof(buf)); /* desc */
> +ast->deint_id = AV_RL32(buf);
>  get_str8(pb, buf, sizeof(buf)); /* desc */
>  }
>  st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
>  st->codec->codec_tag  = AV_RL32(buf);
>  st->codec->codec_id   = ff_codec_get_id(ff_rm_codec_tags,
>  st->codec->codec_tag);
> +
> +switch (ast->deint_id) {
> +case DEINT_ID_GENR:
> +case DEINT_ID_INT0:
> +case DEINT_ID_INT4:
> +case DEINT_ID_SIPR:
> +case DEINT_ID_VBRS:
> +case DEINT_ID_VBRF:
> +break;
> +default:
> +av_log(NULL,0,"Unknown interleaver %X\n", ast->deint_id);
> +return -1;

AVERROR_INVALIDDATA please

> +}
>  switch (st->codec->codec_id) {
>  case CODEC_ID_AC3:
>  st->need_parsing = AVSTREAM_PARSE_FULL;
> @@ -704,10 +727,9 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
>  if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, 
> ×tamp))
>  return -1; //got partial frame
>  } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
> -if ((st->codec->codec_id == CODEC_ID_RA_288) ||
> -(st->codec->codec_id == CODEC_ID_COOK) ||
> -(st->codec->codec_id == CODEC_ID_ATRAC3) ||
> -(st->codec->codec_id == CODEC_ID_SIPR)) {
> +if ((ast->deint_id == DEINT_ID_GENR) ||
> +(ast->deint_id == DEINT_ID_INT4) ||
> +(ast->deint_id == DEINT_ID_SIPR)) {
>  int x;
>  int sps = ast->sub_packet_size;
>  int cfs = ast->coded_framesize;
> @@ -720,30 +742,30 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
>  if (!y)
>  ast->audiotimestamp = timestamp;
>  
> -switch(st->codec->codec_id) {
> -case CODEC_ID_RA_288:
> +switch(ast->deint_id) {
> +case DEINT_ID_INT4:

a space between switch and ( would be nice

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] Use deinterleavers for demangling audio packets in RealMedia.

2011-08-27 Thread Kostya Shishkov
Unlike other containers RealMedia stores its audio packets in scrambled form,
with interleaver ID preceeding audio codec ID. Currently deinterleaving
decision is tied to the codec while it's possible to have non-default
deinterleaver with audio codec (like Int0 deinterleaver instead of specific
one for Sipro).

This also fixes playback of
http://www.cccp-project.net/beta/test_files/mega_weird_audio/Mega_Weird_Audio_2ch_RA5_SIPR.ra
---
 libavformat/rmdec.c |   46 ++
 1 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 7cf5720..9c0a3ff 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -26,6 +26,13 @@
 #include "riff.h"
 #include "rm.h"
 
+#define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///< interleaving for 
Cooker/Atrac
+#define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///< no interleaving needed
+#define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///< interleaving for 28.8
+#define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///< interleaving for Sipro
+#define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///< VBR case for AAC
+#define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///< VBR case for AAC
+
 struct RMStream {
 AVPacket pkt;  ///< place to store merged video frame / reordered 
audio data
 int videobufsize;  ///< current assembled frame size
@@ -39,6 +46,7 @@ struct RMStream {
 int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling 
parameters from container
 int audio_framesize; /// Audio frame size from container
 int sub_packet_lengths[16]; /// Length of each subpacket
+int32_t deint_id;  ///< deinterleaver used in audio stream
 };
 
 typedef struct {
@@ -147,6 +155,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, 
AVIOContext *pb,
 st->codec->channels = 1;
 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
 st->codec->codec_id = CODEC_ID_RA_144;
+ast->deint_id = DEINT_ID_INT0;
 } else {
 int flavor, sub_packet_h, coded_framesize, sub_packet_size;
 int codecdata_length;
@@ -172,17 +181,31 @@ static int rm_read_audio_stream_info(AVFormatContext *s, 
AVIOContext *pb,
 avio_rb32(pb);
 st->codec->channels = avio_rb16(pb);
 if (version == 5) {
-avio_rb32(pb);
+ast->deint_id = avio_rl32(pb);
 avio_read(pb, buf, 4);
 buf[4] = 0;
 } else {
 get_str8(pb, buf, sizeof(buf)); /* desc */
+ast->deint_id = AV_RL32(buf);
 get_str8(pb, buf, sizeof(buf)); /* desc */
 }
 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
 st->codec->codec_tag  = AV_RL32(buf);
 st->codec->codec_id   = ff_codec_get_id(ff_rm_codec_tags,
 st->codec->codec_tag);
+
+switch (ast->deint_id) {
+case DEINT_ID_GENR:
+case DEINT_ID_INT0:
+case DEINT_ID_INT4:
+case DEINT_ID_SIPR:
+case DEINT_ID_VBRS:
+case DEINT_ID_VBRF:
+break;
+default:
+av_log(NULL,0,"Unknown interleaver %X\n", ast->deint_id);
+return -1;
+}
 switch (st->codec->codec_id) {
 case CODEC_ID_AC3:
 st->need_parsing = AVSTREAM_PARSE_FULL;
@@ -704,10 +727,9 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
 if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, ×tamp))
 return -1; //got partial frame
 } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
-if ((st->codec->codec_id == CODEC_ID_RA_288) ||
-(st->codec->codec_id == CODEC_ID_COOK) ||
-(st->codec->codec_id == CODEC_ID_ATRAC3) ||
-(st->codec->codec_id == CODEC_ID_SIPR)) {
+if ((ast->deint_id == DEINT_ID_GENR) ||
+(ast->deint_id == DEINT_ID_INT4) ||
+(ast->deint_id == DEINT_ID_SIPR)) {
 int x;
 int sps = ast->sub_packet_size;
 int cfs = ast->coded_framesize;
@@ -720,30 +742,30 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
 if (!y)
 ast->audiotimestamp = timestamp;
 
-switch(st->codec->codec_id) {
-case CODEC_ID_RA_288:
+switch(ast->deint_id) {
+case DEINT_ID_INT4:
 for (x = 0; x < h/2; x++)
 avio_read(pb, ast->pkt.data+x*2*w+y*cfs, cfs);
 break;
-case CODEC_ID_ATRAC3:
-case CODEC_ID_COOK:
+case DEINT_ID_GENR:
 for (x = 0; x < w/sps; x++)
 avio_read(pb, 
ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
 break;
-case CODEC_ID_SIPR:
+case DEINT_ID_SIPR:
 avio_read(pb, ast->pkt.data + y * w, w);
 break;
  

Re: [libav-devel] [PATCH] Use deinterleavers for demangling audio packets in RealMedia.

2011-08-26 Thread Kostya
On Tue, Aug 16, 2011 at 02:55:56PM -0700, Ronald S. Bultje wrote:
> Hi,
> 
> On Sat, Aug 13, 2011 at 12:02 PM, Kostya Shishkov
>  wrote:
> > Unlike other containers RealMedia stores its audio packets in scrambled 
> > form,
> > with interleaver ID preceeding audio codec ID. Currently deinterleaving
> > decision is tied to the codec while it's possible to have non-default
> > deinterleaver with audio codec (like Int0 deinterleaver instead of specific
> > one for Sipro).
> > ---
> >  libavformat/rmdec.c |   44 +---
> >  1 files changed, 33 insertions(+), 11 deletions(-)
> 
> LGTM.

Found another sample with Sipro and so-called generic deinterleaver (without
Sipro swaps) that I have to test -
http://www.cccp-project.net/beta/test_files/mega_weird_audio/Mega_Weird_Audio_2ch_RA5_SIPR.ra
 
So please don't push it, there will be a better patch(set) soon.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH] Use deinterleavers for demangling audio packets in RealMedia.

2011-08-16 Thread Ronald S. Bultje
Hi,

On Sat, Aug 13, 2011 at 12:02 PM, Kostya Shishkov
 wrote:
> Unlike other containers RealMedia stores its audio packets in scrambled form,
> with interleaver ID preceeding audio codec ID. Currently deinterleaving
> decision is tied to the codec while it's possible to have non-default
> deinterleaver with audio codec (like Int0 deinterleaver instead of specific
> one for Sipro).
> ---
>  libavformat/rmdec.c |   44 +---
>  1 files changed, 33 insertions(+), 11 deletions(-)

LGTM.

Ronald
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] Use deinterleavers for demangling audio packets in RealMedia.

2011-08-13 Thread Kostya Shishkov
Unlike other containers RealMedia stores its audio packets in scrambled form,
with interleaver ID preceeding audio codec ID. Currently deinterleaving
decision is tied to the codec while it's possible to have non-default
deinterleaver with audio codec (like Int0 deinterleaver instead of specific
one for Sipro).
---
 libavformat/rmdec.c |   44 +---
 1 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 3f4d333..f0a246b 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -26,6 +26,13 @@
 #include "riff.h"
 #include "rm.h"
 
+#define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///< interleaving for 
Cooker/Atrac
+#define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///< no interleaving needed
+#define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///< interleaving for 28.8
+#define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///< interleaving for Sipro
+#define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///< VBR case for AAC
+#define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///< VBR case for AAC
+
 struct RMStream {
 AVPacket pkt;  ///< place to store merged video frame / reordered 
audio data
 int videobufsize;  ///< current assembled frame size
@@ -39,6 +46,7 @@ struct RMStream {
 int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling 
parameters from container
 int audio_framesize; /// Audio frame size from container
 int sub_packet_lengths[16]; /// Length of each subpacket
+int32_t deint_id;  ///< deinterleaver used in audio stream
 };
 
 typedef struct {
@@ -147,6 +155,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, 
AVIOContext *pb,
 st->codec->channels = 1;
 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
 st->codec->codec_id = CODEC_ID_RA_144;
+ast->deint_id = DEINT_ID_INT0;
 } else {
 int flavor, sub_packet_h, coded_framesize, sub_packet_size;
 int codecdata_length;
@@ -172,17 +181,31 @@ static int rm_read_audio_stream_info(AVFormatContext *s, 
AVIOContext *pb,
 avio_rb32(pb);
 st->codec->channels = avio_rb16(pb);
 if (version == 5) {
-avio_rb32(pb);
+ast->deint_id = avio_rl32(pb);
 avio_read(pb, buf, 4);
 buf[4] = 0;
 } else {
 get_str8(pb, buf, sizeof(buf)); /* desc */
+ast->deint_id = AV_RL32(buf);
 get_str8(pb, buf, sizeof(buf)); /* desc */
 }
 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
 st->codec->codec_tag  = AV_RL32(buf);
 st->codec->codec_id   = ff_codec_get_id(ff_rm_codec_tags,
 st->codec->codec_tag);
+
+switch (ast->deint_id) {
+case DEINT_ID_GENR:
+case DEINT_ID_INT0:
+case DEINT_ID_INT4:
+case DEINT_ID_SIPR:
+case DEINT_ID_VBRS:
+case DEINT_ID_VBRF:
+break;
+default:
+av_log(NULL,0,"Unknown interleaver %X\n", ast->deint_id);
+return -1;
+}
 switch (st->codec->codec_id) {
 case CODEC_ID_AC3:
 st->need_parsing = AVSTREAM_PARSE_FULL;
@@ -710,10 +733,9 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
 if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq))
 return -1; //got partial frame
 } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
-if ((st->codec->codec_id == CODEC_ID_RA_288) ||
-(st->codec->codec_id == CODEC_ID_COOK) ||
-(st->codec->codec_id == CODEC_ID_ATRAC3) ||
-(st->codec->codec_id == CODEC_ID_SIPR)) {
+if ((ast->deint_id == DEINT_ID_GENR) ||
+(ast->deint_id == DEINT_ID_INT4) ||
+(ast->deint_id == DEINT_ID_SIPR)) {
 int x;
 int sps = ast->sub_packet_size;
 int cfs = ast->coded_framesize;
@@ -726,17 +748,16 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
 if (!y)
 ast->audiotimestamp = timestamp;
 
-switch(st->codec->codec_id) {
-case CODEC_ID_RA_288:
+switch(ast->deint_id) {
+case DEINT_ID_INT4:
 for (x = 0; x < h/2; x++)
 avio_read(pb, ast->pkt.data+x*2*w+y*cfs, cfs);
 break;
-case CODEC_ID_ATRAC3:
-case CODEC_ID_COOK:
+case DEINT_ID_GENR:
 for (x = 0; x < w/sps; x++)
 avio_read(pb, 
ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
 break;
-case CODEC_ID_SIPR:
+case DEINT_ID_SIPR:
 avio_read(pb, ast->pkt.data + y * w, w);
 break;
 }
@@ -749,7 +770,8 @@ ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb,
  ast->sub_packet_cnt = 0;