Merge remote-tracking branch 'qatar/master'
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 3 Jun 2012 00:56:52 +0000 (02:56 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 3 Jun 2012 00:56:52 +0000 (02:56 +0200)
* qatar/master:
  mpegtsenc: Support LATM packetization for AAC
  adtsenc: Don't expose the muxer internals to the rest of lavf
  mpegtsenc: use AVFormatContext for AAC packetization
  mpegtsenc: use AVERROR() for return codes

Conflicts:
libavformat/adts.h
libavformat/mpegtsenc.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
configure
libavformat/Makefile
libavformat/adtsenc.c
libavformat/mpegtsenc.c

diff --cc configure
Simple merge
Simple merge
Simple merge
@@@ -77,9 -75,12 +76,13 @@@ typedef struct MpegTSWrite 
  
      int pmt_start_pid;
      int start_pid;
 +    int m2ts_mode;
  
-     int reemit_pat_pmt;
+     int reemit_pat_pmt; // backward compatibility
+ #define MPEGTS_FLAG_REEMIT_PAT_PMT  0x01
+ #define MPEGTS_FLAG_AAC_LATM        0x02
+     int flags;
  } MpegTSWrite;
  
  /* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */
@@@ -1016,8 -1043,8 +1090,8 @@@ static int mpegts_write_packet_internal
  
          if (pkt->size < 5 || AV_RB32(pkt->data) != 0x0000001) {
              av_log(s, AV_LOG_ERROR, "H.264 bitstream malformed, "
 -                   "no startcode found, use -bsf h264_mp4toannexb\n");
 +                   "no startcode found, use the h264_mp4toannexb bitstream filter (-bsf h264_mp4toannexb)\n");
-             return AVERROR_INVALIDDATA;
+             return AVERROR(EINVAL);
          }
  
          do {
              size = pkt->size+6;
          }
      } else if (st->codec->codec_id == CODEC_ID_AAC) {
-         if (pkt->size < 2)
+         if (pkt->size < 2) {
+             av_log(s, AV_LOG_ERROR, "AAC packet too short\n");
 -            return AVERROR(EINVAL);
 +            return AVERROR_INVALIDDATA;
+         }
          if ((AV_RB16(pkt->data) & 0xfff0) != 0xfff0) {
-             ADTSContext *adts = ts_st->adts;
-             int new_size, err;
-             if (!adts) {
+             int ret;
+             AVPacket pkt2;
+             if (!ts_st->amux) {
                  av_log(s, AV_LOG_ERROR, "AAC bitstream not in ADTS format "
                         "and extradata missing\n");
 -                return AVERROR(EINVAL);
 +                return AVERROR_INVALIDDATA;
              }
-             new_size = ADTS_HEADER_SIZE+adts->pce_size+pkt->size;
-             if ((unsigned)new_size >= INT_MAX)
-                 return AVERROR_INVALIDDATA;
-             data = av_malloc(new_size);
+             av_init_packet(&pkt2);
+             pkt2.data = pkt->data;
+             pkt2.size = pkt->size;
+             ts_st->adata_size = 1024 + pkt->size;
+             ts_st->adata = data = av_malloc(ts_st->adata_size);
+             ts_st->adata_pos = 0;
              if (!data)
                  return AVERROR(ENOMEM);
-             err = ff_adts_write_frame_header(adts, data, pkt->size,
-                                              adts->pce_size);
-             if (err < 0) {
+             ret = av_write_frame(ts_st->amux, &pkt2);
+             if (ret < 0) {
                  av_free(data);
-                 return err;
+                 return ret;
              }
-             if (adts->pce_size) {
-                 memcpy(data+ADTS_HEADER_SIZE, adts->pce_data, adts->pce_size);
-                 adts->pce_size = 0;
+             avio_flush(ts_st->amux->pb);
+             if (ts_st->amux->pb->error < 0) {
+                 av_free(data);
+                 return ts_st->amux->pb->error;
              }
-             memcpy(data+ADTS_HEADER_SIZE+adts->pce_size, pkt->data, pkt->size);
-             buf = data;
-             size = new_size;
+             buf = ts_st->adata;
+             size = ts_st->adata_pos;
          }
      }