avformat: drop redundant MATROSKA_VIDEO_STEREO_MODE_COUNT identifier
[ffmpeg.git] / libavformat / matroska.c
1 /*
2  * Matroska common data
3  * Copyright (c) 2003-2004 The FFmpeg Project
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "libavutil/stereo3d.h"
23
24 #include "matroska.h"
25
26 /* If you add a tag here that is not in ff_codec_bmp_tags[]
27    or ff_codec_wav_tags[], add it also to additional_audio_tags[]
28    or additional_video_tags[] in matroskaenc.c */
29 const CodecTags ff_mkv_codec_tags[]={
30     {"A_AAC"            , AV_CODEC_ID_AAC},
31     {"A_AC3"            , AV_CODEC_ID_AC3},
32     {"A_ALAC"           , AV_CODEC_ID_ALAC},
33     {"A_DTS"            , AV_CODEC_ID_DTS},
34     {"A_EAC3"           , AV_CODEC_ID_EAC3},
35     {"A_FLAC"           , AV_CODEC_ID_FLAC},
36     {"A_MLP"            , AV_CODEC_ID_MLP},
37     {"A_MPEG/L2"        , AV_CODEC_ID_MP2},
38     {"A_MPEG/L1"        , AV_CODEC_ID_MP2},
39     {"A_MPEG/L3"        , AV_CODEC_ID_MP3},
40     {"A_OPUS"           , AV_CODEC_ID_OPUS},
41     {"A_OPUS/EXPERIMENTAL",AV_CODEC_ID_OPUS},
42     {"A_PCM/FLOAT/IEEE" , AV_CODEC_ID_PCM_F32LE},
43     {"A_PCM/FLOAT/IEEE" , AV_CODEC_ID_PCM_F64LE},
44     {"A_PCM/INT/BIG"    , AV_CODEC_ID_PCM_S16BE},
45     {"A_PCM/INT/BIG"    , AV_CODEC_ID_PCM_S24BE},
46     {"A_PCM/INT/BIG"    , AV_CODEC_ID_PCM_S32BE},
47     {"A_PCM/INT/LIT"    , AV_CODEC_ID_PCM_S16LE},
48     {"A_PCM/INT/LIT"    , AV_CODEC_ID_PCM_S24LE},
49     {"A_PCM/INT/LIT"    , AV_CODEC_ID_PCM_S32LE},
50     {"A_PCM/INT/LIT"    , AV_CODEC_ID_PCM_U8},
51     {"A_QUICKTIME/QDM2" , AV_CODEC_ID_QDM2},
52     {"A_REAL/14_4"      , AV_CODEC_ID_RA_144},
53     {"A_REAL/28_8"      , AV_CODEC_ID_RA_288},
54     {"A_REAL/ATRC"      , AV_CODEC_ID_ATRAC3},
55     {"A_REAL/COOK"      , AV_CODEC_ID_COOK},
56     {"A_REAL/SIPR"      , AV_CODEC_ID_SIPR},
57     {"A_TRUEHD"         , AV_CODEC_ID_TRUEHD},
58     {"A_TTA1"           , AV_CODEC_ID_TTA},
59     {"A_VORBIS"         , AV_CODEC_ID_VORBIS},
60     {"A_WAVPACK4"       , AV_CODEC_ID_WAVPACK},
61
62     {"D_WEBVTT/SUBTITLES"   , AV_CODEC_ID_WEBVTT},
63     {"D_WEBVTT/CAPTIONS"    , AV_CODEC_ID_WEBVTT},
64     {"D_WEBVTT/DESCRIPTIONS", AV_CODEC_ID_WEBVTT},
65     {"D_WEBVTT/METADATA"    , AV_CODEC_ID_WEBVTT},
66
67     {"S_TEXT/UTF8"      , AV_CODEC_ID_SUBRIP},
68     {"S_TEXT/UTF8"      , AV_CODEC_ID_TEXT},
69     {"S_TEXT/UTF8"      , AV_CODEC_ID_SRT},
70     {"S_TEXT/ASCII"     , AV_CODEC_ID_TEXT},
71 #if FF_API_ASS_SSA
72     {"S_TEXT/ASS"       , AV_CODEC_ID_SSA},
73     {"S_TEXT/SSA"       , AV_CODEC_ID_SSA},
74     {"S_ASS"            , AV_CODEC_ID_SSA},
75     {"S_SSA"            , AV_CODEC_ID_SSA},
76 #endif
77     {"S_TEXT/ASS"       , AV_CODEC_ID_ASS},
78     {"S_TEXT/SSA"       , AV_CODEC_ID_ASS},
79     {"S_ASS"            , AV_CODEC_ID_ASS},
80     {"S_SSA"            , AV_CODEC_ID_ASS},
81     {"S_VOBSUB"         , AV_CODEC_ID_DVD_SUBTITLE},
82     {"S_DVBSUB"         , AV_CODEC_ID_DVB_SUBTITLE},
83     {"S_HDMV/PGS"       , AV_CODEC_ID_HDMV_PGS_SUBTITLE},
84
85     {"V_DIRAC"          , AV_CODEC_ID_DIRAC},
86     {"V_MJPEG"          , AV_CODEC_ID_MJPEG},
87     {"V_MPEG1"          , AV_CODEC_ID_MPEG1VIDEO},
88     {"V_MPEG2"          , AV_CODEC_ID_MPEG2VIDEO},
89     {"V_MPEG4/ISO/ASP"  , AV_CODEC_ID_MPEG4},
90     {"V_MPEG4/ISO/AP"   , AV_CODEC_ID_MPEG4},
91     {"V_MPEG4/ISO/SP"   , AV_CODEC_ID_MPEG4},
92     {"V_MPEG4/ISO/AVC"  , AV_CODEC_ID_H264},
93     {"V_MPEGH/ISO/HEVC" , AV_CODEC_ID_HEVC},
94     {"V_MPEG4/MS/V3"    , AV_CODEC_ID_MSMPEG4V3},
95     {"V_PRORES"         , AV_CODEC_ID_PRORES},
96     {"V_REAL/RV10"      , AV_CODEC_ID_RV10},
97     {"V_REAL/RV20"      , AV_CODEC_ID_RV20},
98     {"V_REAL/RV30"      , AV_CODEC_ID_RV30},
99     {"V_REAL/RV40"      , AV_CODEC_ID_RV40},
100     {"V_SNOW"           , AV_CODEC_ID_SNOW},
101     {"V_THEORA"         , AV_CODEC_ID_THEORA},
102     {"V_UNCOMPRESSED"   , AV_CODEC_ID_RAWVIDEO},
103     {"V_VP8"            , AV_CODEC_ID_VP8},
104     {"V_VP9"            , AV_CODEC_ID_VP9},
105
106     {""                 , AV_CODEC_ID_NONE}
107 };
108
109 const CodecMime ff_mkv_mime_tags[] = {
110     {"text/plain"                 , AV_CODEC_ID_TEXT},
111     {"image/gif"                  , AV_CODEC_ID_GIF},
112     {"image/jpeg"                 , AV_CODEC_ID_MJPEG},
113     {"image/png"                  , AV_CODEC_ID_PNG},
114     {"image/tiff"                 , AV_CODEC_ID_TIFF},
115     {"application/x-truetype-font", AV_CODEC_ID_TTF},
116     {"application/x-font"         , AV_CODEC_ID_TTF},
117     {"application/vnd.ms-opentype", AV_CODEC_ID_OTF},
118     {"binary"                     , AV_CODEC_ID_BIN_DATA},
119
120     {""                           , AV_CODEC_ID_NONE}
121 };
122
123 const AVMetadataConv ff_mkv_metadata_conv[] = {
124     { "LEAD_PERFORMER", "performer" },
125     { "PART_NUMBER"   , "track"  },
126     { 0 }
127 };
128
129 const char * const ff_matroska_video_stereo_mode[MATROSKA_VIDEO_STEREOMODE_TYPE_NB] = {
130     "mono",
131     "left_right",
132     "bottom_top",
133     "top_bottom",
134     "checkerboard_rl",
135     "checkerboard_lr",
136     "row_interleaved_rl",
137     "row_interleaved_lr",
138     "col_interleaved_rl",
139     "col_interleaved_lr",
140     "anaglyph_cyan_red",
141     "right_left",
142     "anaglyph_green_magenta",
143     "block_lr",
144     "block_rl",
145 };
146
147 const char * const ff_matroska_video_stereo_plane[MATROSKA_VIDEO_STEREO_PLANE_COUNT] = {
148     "left",
149     "right",
150     "background",
151 };
152
153 int ff_mkv_stereo3d_conv(AVStream *st, MatroskaVideoStereoModeType stereo_mode)
154 {
155     AVPacketSideData *sd, *tmp;
156     AVStereo3D *stereo;
157
158     stereo = av_stereo3d_alloc();
159     if (!stereo)
160         return AVERROR(ENOMEM);
161
162     tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
163     if (!tmp) {
164         av_freep(&stereo);
165         return AVERROR(ENOMEM);
166     }
167     st->side_data = tmp;
168     st->nb_side_data++;
169
170     sd = &st->side_data[st->nb_side_data - 1];
171     sd->type = AV_PKT_DATA_STEREO3D;
172     sd->data = (uint8_t *)stereo;
173     sd->size = sizeof(*stereo);
174
175     // note: the missing breaks are intentional
176     switch (stereo_mode) {
177     case MATROSKA_VIDEO_STEREOMODE_TYPE_MONO:
178         stereo->type = AV_STEREO3D_2D;
179         break;
180     case MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT:
181         stereo->flags |= AV_STEREO3D_FLAG_INVERT;
182     case MATROSKA_VIDEO_STEREOMODE_TYPE_LEFT_RIGHT:
183         stereo->type = AV_STEREO3D_SIDEBYSIDE;
184         break;
185     case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTTOM_TOP:
186         stereo->flags |= AV_STEREO3D_FLAG_INVERT;
187     case MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM:
188         stereo->type = AV_STEREO3D_TOPBOTTOM;
189         break;
190     case MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_RL:
191         stereo->flags |= AV_STEREO3D_FLAG_INVERT;
192     case MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_LR:
193         stereo->type = AV_STEREO3D_CHECKERBOARD;
194         break;
195     case MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_RL:
196         stereo->flags |= AV_STEREO3D_FLAG_INVERT;
197     case MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_LR:
198         stereo->type = AV_STEREO3D_LINES;
199         break;
200     case MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_RL:
201         stereo->flags |= AV_STEREO3D_FLAG_INVERT;
202     case MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_LR:
203         stereo->type = AV_STEREO3D_COLUMNS;
204         break;
205     case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_RL:
206         stereo->flags |= AV_STEREO3D_FLAG_INVERT;
207     case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_LR:
208         stereo->type = AV_STEREO3D_FRAMESEQUENCE;
209         break;
210     }
211
212     return 0;
213 }