FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/omaenc.c
Date: 2022-12-09 07:38:14
Exec Total Coverage
Lines: 30 42 71.4%
Functions: 1 1 100.0%
Branches: 7 13 53.8%

Line Branch Exec Source
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 2 static av_cold int oma_write_header(AVFormatContext *s)
31 {
32 AVCodecParameters *par;
33 int srate_index;
34 int isjointstereo;
35
36 2 par = s->streams[0]->codecpar;
37 /* check for support of the format first */
38
39 4 for (srate_index = 0; ; srate_index++) {
40
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (ff_oma_srate_tab[srate_index] == 0) {
41 av_log(s, AV_LOG_ERROR, "Sample rate %d not supported in OpenMG audio\n",
42 par->sample_rate);
43 return AVERROR(EINVAL);
44 }
45
46
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (ff_oma_srate_tab[srate_index] * 100 == par->sample_rate)
47 2 break;
48 }
49
50 /* Metadata; OpenMG does not support ID3v2.4 */
51 2 ff_id3v2_write_simple(s, 3, ID3v2_EA3_MAGIC);
52
53 2 ffio_wfourcc(s->pb, "EA3\0");
54 2 avio_w8(s->pb, EA3_HEADER_SIZE >> 7);
55 2 avio_w8(s->pb, EA3_HEADER_SIZE & 0x7F);
56 2 avio_wl16(s->pb, 0xFFFF); /* not encrypted */
57 2 ffio_fill(s->pb, 0, 6 * 4); /* Padding + DRM id */
58
59
2/3
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 switch (par->codec_tag) {
60 1 case OMA_CODECID_ATRAC3:
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (par->ch_layout.nb_channels != 2) {
62 av_log(s, AV_LOG_ERROR, "ATRAC3 in OMA is only supported with 2 channels\n");
63 return AVERROR(EINVAL);
64 }
65
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (par->extradata_size == 14) /* WAV format extradata */
66 1 isjointstereo = par->extradata[6] != 0;
67 else if(par->extradata_size == 10) /* RM format extradata */
68 isjointstereo = par->extradata[8] == 0x12;
69 else {
70 av_log(s, AV_LOG_ERROR, "ATRAC3: Unsupported extradata size\n");
71 return AVERROR(EINVAL);
72 }
73 1 avio_wb32(s->pb, (OMA_CODECID_ATRAC3 << 24) |
74 1 (isjointstereo << 17) |
75 1 (srate_index << 13) |
76 1 (par->block_align/8));
77 1 break;
78 1 case OMA_CODECID_ATRAC3P:
79 1 avio_wb32(s->pb, (OMA_CODECID_ATRAC3P << 24) |
80 1 (srate_index << 13) |
81 1 (par->ch_layout.nb_channels << 10) |
82 1 (par->block_align/8 - 1));
83 1 break;
84 default:
85 av_log(s, AV_LOG_ERROR, "unsupported codec tag %s for write\n",
86 av_fourcc2str(par->codec_tag));
87 return AVERROR(EINVAL);
88 }
89 2 ffio_fill(s->pb, 0, EA3_HEADER_SIZE - 36); /* Padding */
90
91 2 return 0;
92 }
93
94 const AVOutputFormat ff_oma_muxer = {
95 .name = "oma",
96 .long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"),
97 .mime_type = "audio/x-oma",
98 .extensions = "oma",
99 .audio_codec = AV_CODEC_ID_ATRAC3,
100 .write_header = oma_write_header,
101 .write_packet = ff_raw_write_packet,
102 .codec_tag = ff_oma_codec_tags_list,
103 .flags = AVFMT_NOTIMESTAMPS,
104 };
105