]> git.sesse.net Git - ffmpeg/blob - libavformat/nut.c
Merge commit 'a1bcc76e6036e78f25cbb7323c145056cfca9d93'
[ffmpeg] / libavformat / nut.c
1 /*
2  * nut
3  * Copyright (c) 2004-2007 Michael Niedermayer
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/mathematics.h"
23 #include "libavutil/tree.h"
24 #include "nut.h"
25 #include "internal.h"
26
27 const AVCodecTag ff_nut_subtitle_tags[] = {
28     { AV_CODEC_ID_TEXT        , MKTAG('U', 'T', 'F', '8') },
29     { AV_CODEC_ID_SSA         , MKTAG('S', 'S', 'A',  0 ) },
30     { AV_CODEC_ID_DVD_SUBTITLE, MKTAG('D', 'V', 'D', 'S') },
31     { AV_CODEC_ID_DVB_SUBTITLE, MKTAG('D', 'V', 'B', 'S') },
32     { AV_CODEC_ID_DVB_TELETEXT, MKTAG('D', 'V', 'B', 'T') },
33     { AV_CODEC_ID_NONE        , 0                         }
34 };
35
36 const AVCodecTag ff_nut_video_tags[] = {
37     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 15 ) },
38     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 15 ) },
39     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 16 ) },
40     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 16 ) },
41     { AV_CODEC_ID_RAWVIDEO, MKTAG(15 , 'B', 'G', 'R') },
42     { AV_CODEC_ID_RAWVIDEO, MKTAG(15 , 'R', 'G', 'B') },
43     { AV_CODEC_ID_RAWVIDEO, MKTAG(16 , 'B', 'G', 'R') },
44     { AV_CODEC_ID_RAWVIDEO, MKTAG(16 , 'R', 'G', 'B') },
45     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 12 ) },
46     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 12 ) },
47     { AV_CODEC_ID_RAWVIDEO, MKTAG(12 , 'B', 'G', 'R') },
48     { AV_CODEC_ID_RAWVIDEO, MKTAG(12 , 'R', 'G', 'B') },
49     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 'A') },
50     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B',  0 ) },
51     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 'A') },
52     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R',  0 ) },
53     { AV_CODEC_ID_RAWVIDEO, MKTAG('A', 'B', 'G', 'R') },
54     { AV_CODEC_ID_RAWVIDEO, MKTAG( 0 , 'B', 'G', 'R') },
55     { AV_CODEC_ID_RAWVIDEO, MKTAG('A', 'R', 'G', 'B') },
56     { AV_CODEC_ID_RAWVIDEO, MKTAG( 0 , 'R', 'G', 'B') },
57     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 24 ) },
58     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 24 ) },
59     { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '1', '1', 'P') },
60     { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '2', '2', 'P') },
61     { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '2', '2', 'P') },
62     { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '0', 'P') },
63     { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '0', 'P') },
64     { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '4', 'P') },
65     { AV_CODEC_ID_RAWVIDEO, MKTAG('4', '4', '4', 'P') },
66     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', '1', 'W', '0') },
67     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', '0', 'W', '1') },
68     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R',  8 ) },
69     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B',  8 ) },
70     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R',  4 ) },
71     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B',  4 ) },
72     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', '4', 'B', 'Y') },
73     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', '4', 'B', 'Y') },
74     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 48 ) },
75     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 48 ) },
76     { AV_CODEC_ID_RAWVIDEO, MKTAG(48 , 'B', 'G', 'R') },
77     { AV_CODEC_ID_RAWVIDEO, MKTAG(48 , 'R', 'G', 'B') },
78     { AV_CODEC_ID_RAWVIDEO, MKTAG('B', 'R', 'A', 64 ) },
79     { AV_CODEC_ID_RAWVIDEO, MKTAG('R', 'B', 'A', 64 ) },
80     { AV_CODEC_ID_RAWVIDEO, MKTAG(64 , 'B', 'R', 'A') },
81     { AV_CODEC_ID_RAWVIDEO, MKTAG(64 , 'R', 'B', 'A') },
82     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 10 ) },
83     { AV_CODEC_ID_RAWVIDEO, MKTAG(10 , 11 , '3', 'Y') },
84     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10 , 10 ) },
85     { AV_CODEC_ID_RAWVIDEO, MKTAG(10 , 10 , '3', 'Y') },
86     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3',  0 , 10 ) },
87     { AV_CODEC_ID_RAWVIDEO, MKTAG(10 ,  0 , '3', 'Y') },
88     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 12 ) },
89     { AV_CODEC_ID_RAWVIDEO, MKTAG(12 , 11 , '3', 'Y') },
90     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10 , 12 ) },
91     { AV_CODEC_ID_RAWVIDEO, MKTAG(12 , 10 , '3', 'Y') },
92     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3',  0 , 12 ) },
93     { AV_CODEC_ID_RAWVIDEO, MKTAG(12 ,  0 , '3', 'Y') },
94     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 14 ) },
95     { AV_CODEC_ID_RAWVIDEO, MKTAG(14 , 11 , '3', 'Y') },
96     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10 , 14 ) },
97     { AV_CODEC_ID_RAWVIDEO, MKTAG(14 , 10 , '3', 'Y') },
98     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3',  0 , 14 ) },
99     { AV_CODEC_ID_RAWVIDEO, MKTAG(14 ,  0 , '3', 'Y') },
100     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '1',  0 , 16 ) },
101     { AV_CODEC_ID_RAWVIDEO, MKTAG(16 ,  0 , '1', 'Y') },
102     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 16 ) },
103     { AV_CODEC_ID_RAWVIDEO, MKTAG(16 , 11 , '3', 'Y') },
104     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10 , 16 ) },
105     { AV_CODEC_ID_RAWVIDEO, MKTAG(16 , 10 , '3', 'Y') },
106     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '3',  0 , 16 ) },
107     { AV_CODEC_ID_RAWVIDEO, MKTAG(16 ,  0 , '3', 'Y') },
108     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 11 ,  8 ) },
109     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 10 ,  8 ) },
110     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '4',  0 ,  8 ) },
111     { AV_CODEC_ID_RAWVIDEO, MKTAG('Y', '2',  0 ,  8 ) },
112     { AV_CODEC_ID_NONE    , 0                         }
113 };
114
115 void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val){
116     int i;
117     for(i=0; i<nut->avf->nb_streams; i++){
118         nut->stream[i].last_pts= av_rescale_rnd(
119             val,
120             time_base.num * (int64_t)nut->stream[i].time_base->den,
121             time_base.den * (int64_t)nut->stream[i].time_base->num,
122             AV_ROUND_DOWN);
123     }
124 }
125
126 int64_t ff_lsb2full(StreamContext *stream, int64_t lsb){
127     int64_t mask = (1<<stream->msb_pts_shift)-1;
128     int64_t delta= stream->last_pts - mask/2;
129     return  ((lsb - delta)&mask) + delta;
130 }
131
132 int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b){
133     return ((a->pos - b->pos) >> 32) - ((b->pos - a->pos) >> 32);
134 }
135
136 int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b){
137     return ((a->ts - b->ts) >> 32) - ((b->ts - a->ts) >> 32);
138 }
139
140 void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){
141     Syncpoint *sp= av_mallocz(sizeof(Syncpoint));
142     struct AVTreeNode *node= av_mallocz(av_tree_node_size);
143
144     sp->pos= pos;
145     sp->back_ptr= back_ptr;
146     sp->ts= ts;
147     av_tree_insert(&nut->syncpoints, sp, (void *) ff_nut_sp_pos_cmp, &node);
148     if(node){
149         av_free(sp);
150         av_free(node);
151     }
152 }
153
154 static int enu_free(void *opaque, void *elem)
155 {
156     av_free(elem);
157     return 0;
158 }
159
160 void ff_nut_free_sp(NUTContext *nut)
161 {
162     av_tree_enumerate(nut->syncpoints, NULL, NULL, enu_free);
163     av_tree_destroy(nut->syncpoints);
164 }
165
166 const Dispositions ff_nut_dispositions[] = {
167     {"default"     , AV_DISPOSITION_DEFAULT},
168     {"dub"         , AV_DISPOSITION_DUB},
169     {"original"    , AV_DISPOSITION_ORIGINAL},
170     {"comment"     , AV_DISPOSITION_COMMENT},
171     {"lyrics"      , AV_DISPOSITION_LYRICS},
172     {"karaoke"     , AV_DISPOSITION_KARAOKE},
173     {""            , 0}
174 };
175
176 const AVMetadataConv ff_nut_metadata_conv[] = {
177     { "Author",         "artist"      },
178     { "X-CreationTime", "date"        },
179     { "CreationTime",   "date"        },
180     { "SourceFilename", "filename"    },
181     { "X-Language",     "language"    },
182     { "X-Disposition",  "disposition" },
183     { "X-Replaces",     "replaces"    },
184     { "X-Depends",      "depends"     },
185     { "X-Uses",         "uses"        },
186     { "X-UsesFont",     "usesfont"    },
187     { 0 },
188 };