mov: Rework stsc index validation
[libav.git] / libavformat / matroska.c
CommitLineData
08abe0fd 1/*
b061d892 2 * Matroska common data
41ed7ab4 3 * Copyright (c) 2003-2004 The FFmpeg project
08abe0fd 4 *
2912e87a 5 * This file is part of Libav.
b78e7197 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
08abe0fd
MN
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
b78e7197 10 * version 2.1 of the License, or (at your option) any later version.
08abe0fd 11 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
08abe0fd
MN
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
2912e87a 18 * License along with Libav; if not, write to the Free Software
5509bffa 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
08abe0fd
MN
20 */
21
d4ae8ac9
VG
22#include "libavutil/stereo3d.h"
23
b061d892 24#include "matroska.h"
08abe0fd 25
73a727f3 26const CodecTags ff_mkv_codec_tags[]={
36ef5369
AK
27 {"A_AAC" , AV_CODEC_ID_AAC},
28 {"A_AC3" , AV_CODEC_ID_AC3},
8071dca3 29 {"A_ALAC" , AV_CODEC_ID_ALAC},
36ef5369
AK
30 {"A_DTS" , AV_CODEC_ID_DTS},
31 {"A_EAC3" , AV_CODEC_ID_EAC3},
32 {"A_FLAC" , AV_CODEC_ID_FLAC},
33 {"A_MLP" , AV_CODEC_ID_MLP},
34 {"A_MPEG/L2" , AV_CODEC_ID_MP2},
35 {"A_MPEG/L1" , AV_CODEC_ID_MP2},
36 {"A_MPEG/L3" , AV_CODEC_ID_MP3},
141fdc76 37 {"A_OPUS" , AV_CODEC_ID_OPUS},
36ef5369
AK
38 {"A_PCM/FLOAT/IEEE" , AV_CODEC_ID_PCM_F32LE},
39 {"A_PCM/FLOAT/IEEE" , AV_CODEC_ID_PCM_F64LE},
40 {"A_PCM/INT/BIG" , AV_CODEC_ID_PCM_S16BE},
41 {"A_PCM/INT/BIG" , AV_CODEC_ID_PCM_S24BE},
42 {"A_PCM/INT/BIG" , AV_CODEC_ID_PCM_S32BE},
43 {"A_PCM/INT/LIT" , AV_CODEC_ID_PCM_S16LE},
44 {"A_PCM/INT/LIT" , AV_CODEC_ID_PCM_S24LE},
45 {"A_PCM/INT/LIT" , AV_CODEC_ID_PCM_S32LE},
46 {"A_PCM/INT/LIT" , AV_CODEC_ID_PCM_U8},
47 {"A_QUICKTIME/QDM2" , AV_CODEC_ID_QDM2},
48 {"A_REAL/14_4" , AV_CODEC_ID_RA_144},
49 {"A_REAL/28_8" , AV_CODEC_ID_RA_288},
50 {"A_REAL/ATRC" , AV_CODEC_ID_ATRAC3},
51 {"A_REAL/COOK" , AV_CODEC_ID_COOK},
52 {"A_REAL/SIPR" , AV_CODEC_ID_SIPR},
53 {"A_TRUEHD" , AV_CODEC_ID_TRUEHD},
54 {"A_TTA1" , AV_CODEC_ID_TTA},
55 {"A_VORBIS" , AV_CODEC_ID_VORBIS},
56 {"A_WAVPACK4" , AV_CODEC_ID_WAVPACK},
f7e97aaf 57
36ef5369 58 {"S_TEXT/UTF8" , AV_CODEC_ID_SRT},
bf7be043 59 {"S_TEXT/UTF8" , AV_CODEC_ID_TEXT},
36ef5369
AK
60 {"S_TEXT/ASCII" , AV_CODEC_ID_TEXT},
61 {"S_TEXT/ASS" , AV_CODEC_ID_SSA},
62 {"S_TEXT/SSA" , AV_CODEC_ID_SSA},
63 {"S_ASS" , AV_CODEC_ID_SSA},
64 {"S_SSA" , AV_CODEC_ID_SSA},
65 {"S_VOBSUB" , AV_CODEC_ID_DVD_SUBTITLE},
66a0ac0a 66 {"S_DVBSUB" , AV_CODEC_ID_DVB_SUBTITLE},
36ef5369 67 {"S_HDMV/PGS" , AV_CODEC_ID_HDMV_PGS_SUBTITLE},
f7e97aaf 68
d42809f9 69 {"V_AV1" , AV_CODEC_ID_AV1},
36ef5369
AK
70 {"V_DIRAC" , AV_CODEC_ID_DIRAC},
71 {"V_MJPEG" , AV_CODEC_ID_MJPEG},
72 {"V_MPEG1" , AV_CODEC_ID_MPEG1VIDEO},
73 {"V_MPEG2" , AV_CODEC_ID_MPEG2VIDEO},
74 {"V_MPEG4/ISO/ASP" , AV_CODEC_ID_MPEG4},
75 {"V_MPEG4/ISO/AP" , AV_CODEC_ID_MPEG4},
76 {"V_MPEG4/ISO/SP" , AV_CODEC_ID_MPEG4},
77 {"V_MPEG4/ISO/AVC" , AV_CODEC_ID_H264},
959bea13 78 {"V_MPEGH/ISO/HEVC" , AV_CODEC_ID_HEVC},
36ef5369 79 {"V_MPEG4/MS/V3" , AV_CODEC_ID_MSMPEG4V3},
117d8c6d 80 {"V_PRORES" , AV_CODEC_ID_PRORES},
36ef5369
AK
81 {"V_REAL/RV10" , AV_CODEC_ID_RV10},
82 {"V_REAL/RV20" , AV_CODEC_ID_RV20},
83 {"V_REAL/RV30" , AV_CODEC_ID_RV30},
84 {"V_REAL/RV40" , AV_CODEC_ID_RV40},
36ef5369
AK
85 {"V_THEORA" , AV_CODEC_ID_THEORA},
86 {"V_UNCOMPRESSED" , AV_CODEC_ID_RAWVIDEO},
87 {"V_VP8" , AV_CODEC_ID_VP8},
66aabd76 88 {"V_VP9" , AV_CODEC_ID_VP9},
737dccfc 89
36ef5369 90 {"" , AV_CODEC_ID_NONE}
70596d04 91};
f8d7c9d3 92
c4d37cd9 93const CodecMime ff_mkv_image_mime_tags[] = {
36ef5369
AK
94 {"image/gif" , AV_CODEC_ID_GIF},
95 {"image/jpeg" , AV_CODEC_ID_MJPEG},
96 {"image/png" , AV_CODEC_ID_PNG},
97 {"image/tiff" , AV_CODEC_ID_TIFF},
c4d37cd9 98
99 {"" , AV_CODEC_ID_NONE}
100};
101
102const CodecMime ff_mkv_mime_tags[] = {
103 {"text/plain" , AV_CODEC_ID_TEXT},
36ef5369
AK
104 {"application/x-truetype-font", AV_CODEC_ID_TTF},
105 {"application/x-font" , AV_CODEC_ID_TTF},
f8d7c9d3 106
36ef5369 107 {"" , AV_CODEC_ID_NONE}
f8d7c9d3 108};
719e721a
AJ
109
110const AVMetadataConv ff_mkv_metadata_conv[] = {
ca76a119 111 { "LEAD_PERFORMER", "performer" },
719e721a
AJ
112 { "PART_NUMBER" , "track" },
113 { 0 }
114};
d4ae8ac9
VG
115
116int ff_mkv_stereo3d_conv(AVStream *st, MatroskaVideoStereoModeType stereo_mode)
117{
d4ae8ac9 118 AVStereo3D *stereo;
12ab667e 119 int ret;
d4ae8ac9
VG
120
121 stereo = av_stereo3d_alloc();
122 if (!stereo)
123 return AVERROR(ENOMEM);
124
d4ae8ac9
VG
125 // note: the missing breaks are intentional
126 switch (stereo_mode) {
127 case MATROSKA_VIDEO_STEREOMODE_TYPE_MONO:
128 stereo->type = AV_STEREO3D_2D;
129 break;
130 case MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT:
131 stereo->flags |= AV_STEREO3D_FLAG_INVERT;
132 case MATROSKA_VIDEO_STEREOMODE_TYPE_LEFT_RIGHT:
133 stereo->type = AV_STEREO3D_SIDEBYSIDE;
134 break;
135 case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTTOM_TOP:
136 stereo->flags |= AV_STEREO3D_FLAG_INVERT;
137 case MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM:
138 stereo->type = AV_STEREO3D_TOPBOTTOM;
139 break;
140 case MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_RL:
141 stereo->flags |= AV_STEREO3D_FLAG_INVERT;
142 case MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_LR:
143 stereo->type = AV_STEREO3D_CHECKERBOARD;
144 break;
145 case MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_RL:
146 stereo->flags |= AV_STEREO3D_FLAG_INVERT;
147 case MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_LR:
148 stereo->type = AV_STEREO3D_LINES;
149 break;
150 case MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_RL:
151 stereo->flags |= AV_STEREO3D_FLAG_INVERT;
152 case MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_LR:
153 stereo->type = AV_STEREO3D_COLUMNS;
154 break;
155 case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_RL:
156 stereo->flags |= AV_STEREO3D_FLAG_INVERT;
157 case MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_LR:
158 stereo->type = AV_STEREO3D_FRAMESEQUENCE;
159 break;
160 }
161
12ab667e
JA
162 ret = av_stream_add_side_data(st, AV_PKT_DATA_STEREO3D, (uint8_t *)stereo,
163 sizeof(*stereo));
164 if (ret < 0) {
165 av_freep(&stereo);
166 return ret;
167 }
168
d4ae8ac9
VG
169 return 0;
170}