LCOV - code coverage report
Current view: top level - libavformat - omaenc.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 44 0.0 %
Date: 2017-12-11 04:34:20 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Sony OpenMG (OMA) muxer
       3             :  *
       4             :  * Copyright (c) 2011 Michael Karcher
       5             :  *
       6             :  * This file is part of FFmpeg.
       7             :  *
       8             :  * FFmpeg is free software; you can redistribute it and/or
       9             :  * modify it under the terms of the GNU Lesser General Public
      10             :  * License as published by the Free Software Foundation; either
      11             :  * version 2.1 of the License, or (at your option) any later version.
      12             :  *
      13             :  * FFmpeg is distributed in the hope that it will be useful,
      14             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :  * Lesser General Public License for more details.
      17             :  *
      18             :  * You should have received a copy of the GNU Lesser General Public
      19             :  * License along with FFmpeg; if not, write to the Free Software
      20             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      21             :  */
      22             : 
      23             : #include "avformat.h"
      24             : #include "avio_internal.h"
      25             : #include "id3v2.h"
      26             : #include "internal.h"
      27             : #include "oma.h"
      28             : #include "rawenc.h"
      29             : 
      30           0 : static av_cold int oma_write_header(AVFormatContext *s)
      31             : {
      32             :     int i;
      33             :     AVCodecParameters *par;
      34             :     int srate_index;
      35             :     int isjointstereo;
      36             : 
      37           0 :     par = s->streams[0]->codecpar;
      38             :     /* check for support of the format first */
      39             : 
      40           0 :     for (srate_index = 0; ; srate_index++) {
      41           0 :         if (ff_oma_srate_tab[srate_index] == 0) {
      42           0 :             av_log(s, AV_LOG_ERROR, "Sample rate %d not supported in OpenMG audio\n",
      43             :                    par->sample_rate);
      44           0 :             return AVERROR(EINVAL);
      45             :         }
      46             : 
      47           0 :         if (ff_oma_srate_tab[srate_index] * 100 == par->sample_rate)
      48           0 :             break;
      49             :     }
      50             : 
      51             :     /* Metadata; OpenMG does not support ID3v2.4 */
      52           0 :     ff_id3v2_write_simple(s, 3, ID3v2_EA3_MAGIC);
      53             : 
      54           0 :     ffio_wfourcc(s->pb, "EA3\0");
      55           0 :     avio_w8(s->pb, EA3_HEADER_SIZE >> 7);
      56           0 :     avio_w8(s->pb, EA3_HEADER_SIZE & 0x7F);
      57           0 :     avio_wl16(s->pb, 0xFFFF);       /* not encrypted */
      58           0 :     for (i = 0; i < 6; i++)
      59           0 :         avio_wl32(s->pb, 0);        /* Padding + DRM id */
      60             : 
      61           0 :     switch (par->codec_tag) {
      62           0 :     case OMA_CODECID_ATRAC3:
      63           0 :         if (par->channels != 2) {
      64           0 :             av_log(s, AV_LOG_ERROR, "ATRAC3 in OMA is only supported with 2 channels\n");
      65           0 :             return AVERROR(EINVAL);
      66             :         }
      67           0 :         if (par->extradata_size == 14) /* WAV format extradata */
      68           0 :             isjointstereo = par->extradata[6] != 0;
      69           0 :         else if(par->extradata_size == 10) /* RM format extradata */
      70           0 :             isjointstereo = par->extradata[8] == 0x12;
      71             :         else {
      72           0 :             av_log(s, AV_LOG_ERROR, "ATRAC3: Unsupported extradata size\n");
      73           0 :             return AVERROR(EINVAL);
      74             :         }
      75           0 :         avio_wb32(s->pb, (OMA_CODECID_ATRAC3 << 24) |
      76           0 :                          (isjointstereo << 17) |
      77           0 :                          (srate_index << 13) |
      78           0 :                          (par->block_align/8));
      79           0 :         break;
      80           0 :     case OMA_CODECID_ATRAC3P:
      81           0 :         avio_wb32(s->pb, (OMA_CODECID_ATRAC3P << 24) |
      82           0 :                          (srate_index << 13) |
      83           0 :                          (par->channels << 10) |
      84           0 :                          (par->block_align/8 - 1));
      85           0 :         break;
      86           0 :     default:
      87           0 :         av_log(s, AV_LOG_ERROR, "unsupported codec tag %s for write\n",
      88           0 :                av_fourcc2str(par->codec_tag));
      89           0 :         return AVERROR(EINVAL);
      90             :     }
      91           0 :     for (i = 0; i < (EA3_HEADER_SIZE - 36)/4; i++)
      92           0 :         avio_wl32(s->pb, 0);        /* Padding */
      93             : 
      94           0 :     return 0;
      95             : }
      96             : 
      97             : AVOutputFormat ff_oma_muxer = {
      98             :     .name              = "oma",
      99             :     .long_name         = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
     100             :     .mime_type         = "audio/x-oma",
     101             :     .extensions        = "oma",
     102             :     .audio_codec       = AV_CODEC_ID_ATRAC3,
     103             :     .write_header      = oma_write_header,
     104             :     .write_packet      = ff_raw_write_packet,
     105             :     .codec_tag         = (const AVCodecTag* const []){ff_oma_codec_tags, 0},
     106             :     .flags             = AVFMT_NOTIMESTAMPS,
     107             : };

Generated by: LCOV version 1.13