00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/mathematics.h"
00023 #include "libavutil/tree.h"
00024 #include "nut.h"
00025 #include "internal.h"
00026
00027 const AVCodecTag ff_nut_subtitle_tags[] = {
00028 { CODEC_ID_TEXT , MKTAG('U', 'T', 'F', '8') },
00029 { CODEC_ID_SSA , MKTAG('S', 'S', 'A', 0 ) },
00030 { CODEC_ID_DVD_SUBTITLE, MKTAG('D', 'V', 'D', 'S') },
00031 { CODEC_ID_DVB_SUBTITLE, MKTAG('D', 'V', 'B', 'S') },
00032 { CODEC_ID_NONE , 0 }
00033 };
00034
00035 const AVCodecTag ff_nut_video_tags[] = {
00036 { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 15 ) },
00037 { CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 15 ) },
00038 { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 16 ) },
00039 { CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 16 ) },
00040 { CODEC_ID_RAWVIDEO, MKTAG(15 , 'B', 'G', 'R') },
00041 { CODEC_ID_RAWVIDEO, MKTAG(15 , 'R', 'G', 'B') },
00042 { CODEC_ID_RAWVIDEO, MKTAG(16 , 'B', 'G', 'R') },
00043 { CODEC_ID_RAWVIDEO, MKTAG(16 , 'R', 'G', 'B') },
00044 { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 12 ) },
00045 { CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 12 ) },
00046 { CODEC_ID_RAWVIDEO, MKTAG(12 , 'B', 'G', 'R') },
00047 { CODEC_ID_RAWVIDEO, MKTAG(12 , 'R', 'G', 'B') },
00048 { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 'A') },
00049 { CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 'A') },
00050 { CODEC_ID_RAWVIDEO, MKTAG('A', 'B', 'G', 'R') },
00051 { CODEC_ID_RAWVIDEO, MKTAG('A', 'R', 'G', 'B') },
00052 { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 24 ) },
00053 { CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 24 ) },
00054 { CODEC_ID_RAWVIDEO, MKTAG('4', '1', '1', 'P') },
00055 { CODEC_ID_RAWVIDEO, MKTAG('4', '2', '2', 'P') },
00056 { CODEC_ID_RAWVIDEO, MKTAG('4', '2', '2', 'P') },
00057 { CODEC_ID_RAWVIDEO, MKTAG('4', '4', '0', 'P') },
00058 { CODEC_ID_RAWVIDEO, MKTAG('4', '4', '0', 'P') },
00059 { CODEC_ID_RAWVIDEO, MKTAG('4', '4', '4', 'P') },
00060 { CODEC_ID_RAWVIDEO, MKTAG('4', '4', '4', 'P') },
00061 { CODEC_ID_RAWVIDEO, MKTAG('B', '1', 'W', '0') },
00062 { CODEC_ID_RAWVIDEO, MKTAG('B', '0', 'W', '1') },
00063 { CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 8 ) },
00064 { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 8 ) },
00065 { CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 4 ) },
00066 { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 4 ) },
00067 { CODEC_ID_RAWVIDEO, MKTAG('B', '4', 'B', 'Y') },
00068 { CODEC_ID_RAWVIDEO, MKTAG('R', '4', 'B', 'Y') },
00069 { CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 48 ) },
00070 { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 48 ) },
00071 { CODEC_ID_RAWVIDEO, MKTAG(48 , 'B', 'G', 'R') },
00072 { CODEC_ID_RAWVIDEO, MKTAG(48 , 'R', 'G', 'B') },
00073 { CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 10 ) },
00074 { CODEC_ID_RAWVIDEO, MKTAG(10 , 11 , '3', 'Y') },
00075 { CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10 , 10 ) },
00076 { CODEC_ID_RAWVIDEO, MKTAG(10 , 10 , '3', 'Y') },
00077 { CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 0 , 10 ) },
00078 { CODEC_ID_RAWVIDEO, MKTAG(10 , 0 , '3', 'Y') },
00079 { CODEC_ID_RAWVIDEO, MKTAG('Y', '1', 0 , 16 ) },
00080 { CODEC_ID_RAWVIDEO, MKTAG(16 , 0 , '1', 'Y') },
00081 { CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 16 ) },
00082 { CODEC_ID_RAWVIDEO, MKTAG(16 , 11 , '3', 'Y') },
00083 { CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10 , 16 ) },
00084 { CODEC_ID_RAWVIDEO, MKTAG(16 , 10 , '3', 'Y') },
00085 { CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 0 , 16 ) },
00086 { CODEC_ID_RAWVIDEO, MKTAG(16 , 0 , '3', 'Y') },
00087 { CODEC_ID_RAWVIDEO, MKTAG('Y', '4', 11 , 8 ) },
00088 { CODEC_ID_RAWVIDEO, MKTAG('Y', '2', 0 , 8 ) },
00089 { CODEC_ID_NONE , 0 }
00090 };
00091
00092 void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val){
00093 int i;
00094 for(i=0; i<nut->avf->nb_streams; i++){
00095 nut->stream[i].last_pts= av_rescale_rnd(
00096 val,
00097 time_base.num * (int64_t)nut->stream[i].time_base->den,
00098 time_base.den * (int64_t)nut->stream[i].time_base->num,
00099 AV_ROUND_DOWN);
00100 }
00101 }
00102
00103 int64_t ff_lsb2full(StreamContext *stream, int64_t lsb){
00104 int64_t mask = (1<<stream->msb_pts_shift)-1;
00105 int64_t delta= stream->last_pts - mask/2;
00106 return ((lsb - delta)&mask) + delta;
00107 }
00108
00109 int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b){
00110 return ((a->pos - b->pos) >> 32) - ((b->pos - a->pos) >> 32);
00111 }
00112
00113 int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b){
00114 return ((a->ts - b->ts) >> 32) - ((b->ts - a->ts) >> 32);
00115 }
00116
00117 void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){
00118 Syncpoint *sp= av_mallocz(sizeof(Syncpoint));
00119 struct AVTreeNode *node= av_mallocz(av_tree_node_size);
00120
00121 sp->pos= pos;
00122 sp->back_ptr= back_ptr;
00123 sp->ts= ts;
00124 av_tree_insert(&nut->syncpoints, sp, (void *) ff_nut_sp_pos_cmp, &node);
00125 if(node){
00126 av_free(sp);
00127 av_free(node);
00128 }
00129 }
00130
00131 static int enu_free(void *opaque, void *elem)
00132 {
00133 av_free(elem);
00134 return 0;
00135 }
00136
00137 void ff_nut_free_sp(NUTContext *nut)
00138 {
00139 av_tree_enumerate(nut->syncpoints, NULL, NULL, enu_free);
00140 av_tree_destroy(nut->syncpoints);
00141 }
00142
00143 const Dispositions ff_nut_dispositions[] = {
00144 {"default" , AV_DISPOSITION_DEFAULT},
00145 {"dub" , AV_DISPOSITION_DUB},
00146 {"original" , AV_DISPOSITION_ORIGINAL},
00147 {"comment" , AV_DISPOSITION_COMMENT},
00148 {"lyrics" , AV_DISPOSITION_LYRICS},
00149 {"karaoke" , AV_DISPOSITION_KARAOKE},
00150 {"" , 0}
00151 };
00152
00153 const AVMetadataConv ff_nut_metadata_conv[] = {
00154 { "Author", "artist" },
00155 { "X-CreationTime", "date" },
00156 { "CreationTime", "date" },
00157 { "SourceFilename", "filename" },
00158 { "X-Language", "language" },
00159 { "X-Disposition", "disposition" },
00160 { "X-Replaces", "replaces" },
00161 { "X-Depends", "depends" },
00162 { "X-Uses", "uses" },
00163 { "X-UsesFont", "usesfont" },
00164 { 0 },
00165 };