FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/asf.c
Date: 2022-12-09 07:38:14
Exec Total Coverage
Lines: 45 60 75.0%
Functions: 3 3 100.0%
Branches: 19 30 63.3%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000, 2001 Fabrice Bellard
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "asf.h"
22 #include "demux.h"
23 #include "id3v2.h"
24 #include "internal.h"
25
26 /* List of official tags at http://msdn.microsoft.com/en-us/library/dd743066(VS.85).aspx */
27 const AVMetadataConv ff_asf_metadata_conv[] = {
28 { "WM/AlbumArtist", "album_artist" },
29 { "WM/AlbumTitle", "album" },
30 { "Author", "artist" },
31 { "Description", "comment" },
32 { "WM/Composer", "composer" },
33 { "WM/EncodedBy", "encoded_by" },
34 { "WM/EncodingSettings", "encoder" },
35 { "WM/Genre", "genre" },
36 { "WM/Language", "language" },
37 { "WM/OriginalFilename", "filename" },
38 { "WM/PartOfSet", "disc" },
39 { "WM/Publisher", "publisher" },
40 { "WM/Tool", "encoder" },
41 { "WM/TrackNumber", "track" },
42 { "WM/MediaStationCallSign", "service_provider" },
43 { "WM/MediaStationName", "service_name" },
44 // { "Year" , "date" }, TODO: conversion year<->date
45 { 0 }
46 };
47
48 /* MSDN claims that this should be "compatible with the ID3 frame, APIC",
49 * but in reality this is only loosely similar */
50 3 static int asf_read_picture(AVFormatContext *s, int len)
51 {
52 3 const CodecMime *mime = ff_id3v2_mime_tags;
53 3 enum AVCodecID id = AV_CODEC_ID_NONE;
54 char mimetype[64];
55 3 uint8_t *desc = NULL;
56 3 AVStream *st = NULL;
57 int ret, type, picsize, desc_len;
58
59 /* type + picsize + mime + desc */
60
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (len < 1 + 4 + 2 + 2) {
61 av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len);
62 return AVERROR_INVALIDDATA;
63 }
64
65 /* picture type */
66 3 type = avio_r8(s->pb);
67 3 len--;
68
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) {
69 av_log(s, AV_LOG_WARNING, "Unknown attached picture type: %d.\n", type);
70 type = 0;
71 }
72
73 /* picture data size */
74 3 picsize = avio_rl32(s->pb);
75 3 len -= 4;
76
77 /* picture MIME type */
78 3 len -= avio_get_str16le(s->pb, len, mimetype, sizeof(mimetype));
79
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 while (mime->id != AV_CODEC_ID_NONE) {
80
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (!strncmp(mime->str, mimetype, sizeof(mimetype))) {
81 3 id = mime->id;
82 3 break;
83 }
84 3 mime++;
85 }
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (id == AV_CODEC_ID_NONE) {
87 av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n",
88 mimetype);
89 return 0;
90 }
91
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (picsize >= len) {
93 av_log(s, AV_LOG_ERROR, "Invalid attached picture data size: %d >= %d.\n",
94 picsize, len);
95 return AVERROR_INVALIDDATA;
96 }
97
98 /* picture description */
99 3 desc_len = (len - picsize) * 2 + 1;
100 3 desc = av_malloc(desc_len);
101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!desc)
102 return AVERROR(ENOMEM);
103 3 len -= avio_get_str16le(s->pb, len - picsize, desc, desc_len);
104
105 3 ret = ff_add_attached_pic(s, NULL, s->pb, NULL, picsize);
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0)
107 goto fail;
108 3 st = s->streams[s->nb_streams - 1];
109
110 3 st->codecpar->codec_id = id;
111
112
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (*desc) {
113
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL) < 0)
114 av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");
115 } else
116 1 av_freep(&desc);
117
118
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if (av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0) < 0)
119 av_log(s, AV_LOG_WARNING, "av_dict_set failed.\n");
120
121 3 return 0;
122
123 fail:
124 av_freep(&desc);
125 return ret;
126 }
127
128 1 static int get_id3_tag(AVFormatContext *s, int len)
129 {
130 ID3v2ExtraMeta *id3v2_extra_meta;
131
132 1 ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta, len);
133
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (id3v2_extra_meta) {
134 1 ff_id3v2_parse_apic(s, id3v2_extra_meta);
135 1 ff_id3v2_parse_chapters(s, id3v2_extra_meta);
136 1 ff_id3v2_free_extra_meta(&id3v2_extra_meta);
137 }
138 1 return 0;
139 }
140
141 16 int ff_asf_handle_byte_array(AVFormatContext *s, const char *name,
142 int val_len)
143 {
144
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 13 times.
16 if (!strcmp(name, "WM/Picture")) // handle cover art
145 3 return asf_read_picture(s, val_len);
146
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 12 times.
13 else if (!strcmp(name, "ID3")) // handle ID3 tag
147 1 return get_id3_tag(s, val_len);
148
149 12 return 1;
150 }
151