]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/spdifenc.c
vf_hwmap: Properly free a locally derived device
[ffmpeg] / libavformat / spdifenc.c
index 0e1f1d4c47c9e336142cdb53796f680854e39f6b..6497a8273489d1f0b3fe4716d6b093bac3c07f70 100644 (file)
@@ -32,7 +32,7 @@
 /*
  * Terminology used in specification:
  * data-burst - IEC61937 frame, contains header and encapsuled frame
- * burst-preambule - IEC61937 frame header, contains 16-bits words named Pa, Pb, Pc and Pd
+ * burst-preamble - IEC61937 frame header, contains 16-bit words named Pa, Pb, Pc and Pd
  * burst-payload - encapsuled frame
  * Pa, Pb - syncword - 0xF872, 0x4E1F
  * Pc - burst-info, contains data-type (bits 0-6), error flag (bit 7), data-type-dependent info (bits 8-12)
@@ -50,9 +50,9 @@
 #include "avio_internal.h"
 #include "spdif.h"
 #include "libavcodec/ac3.h"
+#include "libavcodec/adts_parser.h"
 #include "libavcodec/dca.h"
 #include "libavcodec/dca_syncwords.h"
-#include "libavcodec/aacadtsdec.h"
 #include "libavutil/opt.h"
 
 typedef struct IEC61937Context {
@@ -147,7 +147,7 @@ static int spdif_header_eac3(AVFormatContext *s, AVPacket *pkt)
  * DTS type IV (DTS-HD) can be transmitted with various frame repetition
  * periods; longer repetition periods allow for longer packets and therefore
  * higher bitrate. Longer repetition periods mean that the constant bitrate of
- * the outputted IEC 61937 stream is higher.
+ * the output IEC 61937 stream is higher.
  * The repetition period is measured in IEC 60958 frames (4 bytes).
  */
 static int spdif_dts4_subtype(int period)
@@ -319,8 +319,8 @@ static int spdif_header_dts(AVFormatContext *s, AVPacket *pkt)
 
 static const enum IEC61937DataType mpeg_data_type[2][3] = {
     //     LAYER1                      LAYER2                  LAYER3
-    { IEC61937_MPEG2_LAYER1_LSF, IEC61937_MPEG2_LAYER2_LSF, IEC61937_MPEG2_LAYER3_LSF },//MPEG2 LSF
-    { IEC61937_MPEG1_LAYER1,     IEC61937_MPEG1_LAYER23,    IEC61937_MPEG1_LAYER23 },   //MPEG1
+    { IEC61937_MPEG2_LAYER1_LSF, IEC61937_MPEG2_LAYER2_LSF, IEC61937_MPEG2_LAYER3_LSF }, // MPEG-2 LSF
+    { IEC61937_MPEG1_LAYER1,     IEC61937_MPEG1_LAYER23,    IEC61937_MPEG1_LAYER23 },    // MPEG-1
 };
 
 static int spdif_header_mpeg(AVFormatContext *s, AVPacket *pkt)
@@ -349,19 +349,18 @@ static int spdif_header_mpeg(AVFormatContext *s, AVPacket *pkt)
 static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
 {
     IEC61937Context *ctx = s->priv_data;
-    AACADTSHeaderInfo hdr;
-    GetBitContext gbc;
+    uint32_t samples;
+    uint8_t frames;
     int ret;
 
-    init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8);
-    ret = avpriv_aac_parse_header(&gbc, &hdr);
+    ret = av_adts_header_parse(pkt->data, &samples, &frames);
     if (ret < 0) {
         av_log(s, AV_LOG_ERROR, "Wrong AAC file format\n");
-        return AVERROR_INVALIDDATA;
+        return ret;
     }
 
-    ctx->pkt_offset = hdr.samples << 2;
-    switch (hdr.num_aac_frames) {
+    ctx->pkt_offset = samples << 2;
+    switch (frames) {
     case 1:
         ctx->data_type = IEC61937_MPEG2_AAC;
         break;
@@ -373,7 +372,7 @@ static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
         break;
     default:
         av_log(s, AV_LOG_ERROR,
-               "%"PRIu32" samples in AAC frame not supported\n", hdr.samples);
+               "%"PRIu32" samples in AAC frame not supported\n", samples);
         return AVERROR(EINVAL);
     }
     //TODO Data type dependent info (LC profile/SBR)
@@ -398,15 +397,15 @@ static int spdif_header_truehd(AVFormatContext *s, AVPacket *pkt)
 {
     IEC61937Context *ctx = s->priv_data;
     int mat_code_length = 0;
-    const char mat_end_code[16] = { 0xC3, 0xC2, 0xC0, 0xC4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x11 };
+    static const char mat_end_code[16] = { 0xC3, 0xC2, 0xC0, 0xC4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x11 };
 
     if (!ctx->hd_buf_count) {
-        const char mat_start_code[20] = { 0x07, 0x9E, 0x00, 0x03, 0x84, 0x01, 0x01, 0x01, 0x80, 0x00, 0x56, 0xA5, 0x3B, 0xF4, 0x81, 0x83, 0x49, 0x80, 0x77, 0xE0 };
+        static const char mat_start_code[20] = { 0x07, 0x9E, 0x00, 0x03, 0x84, 0x01, 0x01, 0x01, 0x80, 0x00, 0x56, 0xA5, 0x3B, 0xF4, 0x81, 0x83, 0x49, 0x80, 0x77, 0xE0 };
         mat_code_length = sizeof(mat_start_code) + BURST_HEADER_SIZE;
         memcpy(ctx->hd_buf, mat_start_code, sizeof(mat_start_code));
 
     } else if (ctx->hd_buf_count == 12) {
-        const char mat_middle_code[12] = { 0xC3, 0xC1, 0x42, 0x49, 0x3B, 0xFA, 0x82, 0x83, 0x49, 0x80, 0x77, 0xE0 };
+        static const char mat_middle_code[12] = { 0xC3, 0xC1, 0x42, 0x49, 0x3B, 0xFA, 0x82, 0x83, 0x49, 0x80, 0x77, 0xE0 };
         mat_code_length = sizeof(mat_middle_code) + MAT_MIDDLE_CODE_OFFSET;
         memcpy(&ctx->hd_buf[12 * TRUEHD_FRAME_OFFSET - BURST_HEADER_SIZE + MAT_MIDDLE_CODE_OFFSET],
                mat_middle_code, sizeof(mat_middle_code));
@@ -469,7 +468,8 @@ static int spdif_write_header(AVFormatContext *s)
             return AVERROR(ENOMEM);
         break;
     default:
-        av_log(s, AV_LOG_ERROR, "codec not supported\n");
+        avpriv_report_missing_feature(s, "Codec %d",
+                                      s->streams[0]->codecpar->codec_id);
         return AVERROR_PATCHWELCOME;
     }
     return 0;