Advertisement
eejya

Untitled

Oct 15th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.13 KB | None | 0 0
  1. commit 34e0b0863985451c30df06cae45146cdd36aa87e
  2. Author: Eejya <singh.eejya@gmail.com>
  3. Date: Mon Oct 13 22:49:03 2014 +0530
  4.  
  5. Added STL demuxer and decoder
  6.  
  7. diff --git a/Changelog b/Changelog
  8. index b59058b..9626d4a 100644
  9. --- a/Changelog
  10. +++ b/Changelog
  11. @@ -5,6 +5,7 @@ version <next>:
  12. - HEVC/H.265 RTP payload format (draft v6) packetizer
  13. - SUP/PGS subtitle demuxer
  14. - ffprobe -show_pixel_formats option
  15. +- STL subtitle demuxer and decoder
  16.  
  17. version 2.4:
  18. - Icecast protocol
  19. diff --git a/doc/general.texi b/doc/general.texi
  20. index 2252f7b..681c5c9 100644
  21. --- a/doc/general.texi
  22. +++ b/doc/general.texi
  23. @@ -1032,6 +1032,7 @@ performance on systems without hardware floating point support).
  24. @item RealText @tab @tab X @tab @tab X
  25. @item SAMI @tab @tab X @tab @tab X
  26. @item SSA/ASS @tab X @tab X @tab X @tab X
  27. +@item STL @tab @tab X @tab @tab X
  28. @item SubRip (SRT) @tab X @tab X @tab X @tab X
  29. @item SubViewer v1 @tab @tab X @tab @tab X
  30. @item SubViewer @tab @tab X @tab @tab X
  31. diff --git a/libavcodec/Makefile b/libavcodec/Makefile
  32. index 3d70313..1a0072a 100644
  33. --- a/libavcodec/Makefile
  34. +++ b/libavcodec/Makefile
  35. @@ -429,6 +429,7 @@ OBJS-$(CONFIG_SONIC_LS_ENCODER) += sonic.o
  36. OBJS-$(CONFIG_SP5X_DECODER) += sp5xdec.o
  37. OBJS-$(CONFIG_SRT_DECODER) += srtdec.o ass.o
  38. OBJS-$(CONFIG_SRT_ENCODER) += srtenc.o ass_split.o
  39. +OBJS-$(CONFIG_STL_DECODER) += textdec.o ass.o
  40. OBJS-$(CONFIG_SUBRIP_DECODER) += srtdec.o ass.o
  41. OBJS-$(CONFIG_SUBRIP_ENCODER) += srtenc.o ass_split.o
  42. OBJS-$(CONFIG_SUBVIEWER1_DECODER) += textdec.o ass.o
  43. diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
  44. index 7650543..d08abd8 100644
  45. --- a/libavcodec/allcodecs.c
  46. +++ b/libavcodec/allcodecs.c
  47. @@ -490,6 +490,7 @@ void avcodec_register_all(void)
  48. REGISTER_DECODER(REALTEXT, realtext);
  49. REGISTER_DECODER(SAMI, sami);
  50. REGISTER_ENCDEC (SRT, srt);
  51. + REGISTER_DECODER(STL, stl);
  52. REGISTER_ENCDEC (SUBRIP, subrip);
  53. REGISTER_DECODER(SUBVIEWER, subviewer);
  54. REGISTER_DECODER(SUBVIEWER1, subviewer1);
  55. diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
  56. index a5a651a..acd9b03 100644
  57. --- a/libavcodec/avcodec.h
  58. +++ b/libavcodec/avcodec.h
  59. @@ -509,6 +509,7 @@ enum AVCodecID {
  60. AV_CODEC_ID_JACOSUB = MKBETAG('J','S','U','B'),
  61. AV_CODEC_ID_SAMI = MKBETAG('S','A','M','I'),
  62. AV_CODEC_ID_REALTEXT = MKBETAG('R','T','X','T'),
  63. + AV_CODEC_ID_STL = MKBETAG('S','p','T','L'),
  64. AV_CODEC_ID_SUBVIEWER1 = MKBETAG('S','b','V','1'),
  65. AV_CODEC_ID_SUBVIEWER = MKBETAG('S','u','b','V'),
  66. AV_CODEC_ID_SUBRIP = MKBETAG('S','R','i','p'),
  67. diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
  68. index 9e9728b..eeb4505 100644
  69. --- a/libavcodec/codec_desc.c
  70. +++ b/libavcodec/codec_desc.c
  71. @@ -2635,6 +2635,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
  72. .props = AV_CODEC_PROP_TEXT_SUB,
  73. },
  74. {
  75. + .id = AV_CODEC_ID_STL,
  76. + .type = AVMEDIA_TYPE_SUBTITLE,
  77. + .name = "stl",
  78. + .long_name = NULL_IF_CONFIG_SMALL("Spruce subtitle format"),
  79. + .props = AV_CODEC_PROP_TEXT_SUB,
  80. + },
  81. + {
  82. .id = AV_CODEC_ID_SUBVIEWER1,
  83. .type = AVMEDIA_TYPE_SUBTITLE,
  84. .name = "subviewer1",
  85. diff --git a/libavcodec/textdec.c b/libavcodec/textdec.c
  86. index ba189e8..aa84257 100644
  87. --- a/libavcodec/textdec.c
  88. +++ b/libavcodec/textdec.c
  89. @@ -88,7 +88,7 @@ AVCodec ff_text_decoder = {
  90. };
  91. #endif
  92.  
  93. -#if CONFIG_VPLAYER_DECODER || CONFIG_PJS_DECODER || CONFIG_SUBVIEWER1_DECODER
  94. +#if CONFIG_VPLAYER_DECODER || CONFIG_PJS_DECODER || CONFIG_SUBVIEWER1_DECODER || CONFIG_STL_DECODER
  95.  
  96. static int linebreak_init(AVCodecContext *avctx)
  97. {
  98. @@ -113,6 +113,22 @@ AVCodec ff_vplayer_decoder = {
  99. };
  100. #endif
  101.  
  102. +#if CONFIG_STL_DECODER
  103. +#define stl_options options
  104. +DECLARE_CLASS(stl);
  105. +
  106. +AVCodec ff_stl_decoder = {
  107. + .name = "stl",
  108. + .long_name = NULL_IF_CONFIG_SMALL("Spruce subtitle format"),
  109. + .priv_data_size = sizeof(TextContext),
  110. + .type = AVMEDIA_TYPE_SUBTITLE,
  111. + .id = AV_CODEC_ID_STL,
  112. + .decode = text_decode_frame,
  113. + .init = linebreak_init,
  114. + .priv_class = &stl_decoder_class,
  115. +};
  116. +#endif
  117. +
  118. #if CONFIG_PJS_DECODER
  119. #define pjs_options options
  120. DECLARE_CLASS(pjs);
  121. diff --git a/libavformat/Makefile b/libavformat/Makefile
  122. index 86064ea..a64e7ad 100644
  123. --- a/libavformat/Makefile
  124. +++ b/libavformat/Makefile
  125. @@ -433,6 +433,7 @@ OBJS-$(CONFIG_VOBSUB_DEMUXER) += subtitles.o # mpeg demuxer is in the
  126. OBJS-$(CONFIG_VOC_DEMUXER) += vocdec.o voc.o
  127. OBJS-$(CONFIG_VOC_MUXER) += vocenc.o voc.o
  128. OBJS-$(CONFIG_VPLAYER_DEMUXER) += vplayerdec.o subtitles.o
  129. +OBJS-$(CONFIG_STL_DEMUXER) += stldec.o subtitles.o
  130. OBJS-$(CONFIG_VQF_DEMUXER) += vqf.o
  131. OBJS-$(CONFIG_W64_DEMUXER) += wavdec.o w64.o pcm.o
  132. OBJS-$(CONFIG_W64_MUXER) += wavenc.o w64.o
  133. diff --git a/libavformat/allformats.c b/libavformat/allformats.c
  134. index d54ed9b..c1a3a4e 100644
  135. --- a/libavformat/allformats.c
  136. +++ b/libavformat/allformats.c
  137. @@ -258,6 +258,7 @@ void av_register_all(void)
  138. REGISTER_DEMUXER (SBG, sbg);
  139. REGISTER_DEMUXER (SDP, sdp);
  140. REGISTER_DEMUXER (SDR2, sdr2);
  141. + REGISTER_DEMUXER (STL, stl);
  142. #if CONFIG_RTPDEC
  143. ff_register_rtp_dynamic_payload_handlers();
  144. ff_register_rdt_dynamic_payload_handlers();
  145. diff --git a/libavformat/stldec.c b/libavformat/stldec.c
  146. new file mode 100644
  147. index 0000000..9e79720
  148. --- /dev/null
  149. +++ b/libavformat/stldec.c
  150. @@ -0,0 +1,136 @@
  151. +/*
  152. + * Copyright (c) 2014 Eejya Singh
  153. + *
  154. + * This file is part of FFmpeg.
  155. + *
  156. + * FFmpeg is free software; you can redistribute it and/or
  157. + * modify it under the terms of the GNU Lesser General Public
  158. + * License as published by the Free Software Foundation; either
  159. + * version 2.1 of the License, or (at your option) any later version.
  160. + *
  161. + * FFmpeg is distributed in the hope that it will be useful,
  162. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  163. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  164. + * Lesser General Public License for more details.
  165. + *
  166. + * You should have received a copy of the GNU Lesser General Public
  167. + * License along with FFmpeg; if not, write to the Free Software
  168. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  169. + */
  170. +
  171. +/**
  172. + * @file
  173. + * STL subtitles format demuxer
  174. + */
  175. +#include "avformat.h"
  176. +#include "internal.h"
  177. +#include "subtitles.h"
  178. +#include "libavutil/intreadwrite.h"
  179. +#include "libavutil/avstring.h"
  180. +
  181. +typedef struct {
  182. + FFDemuxSubtitlesQueue q;
  183. +} STLContext;
  184. +
  185. +static int stl_probe(AVProbeData *p)
  186. +{
  187. + char c;
  188. + const unsigned char *ptr = p->buf;
  189. +
  190. + if (AV_RB24(ptr) == 0xEFBBBF)
  191. + ptr += 3; /* skip UTF-8 BOM */
  192. + while(*ptr=='\r' || *ptr=='\n' || *ptr=='$' || !strncmp(ptr,"//",2))
  193. + ptr+=ff_subtitles_next_line(ptr);
  194. + if (sscanf(ptr, "%*d:%*d:%*d:%*d , %*d:%*d:%*d:%*d , %c", &c) == 1)
  195. + return AVPROBE_SCORE_MAX;
  196. + return 0;
  197. +}
  198. +static int64_t get_pts(char **buf, int *duration)
  199. +{
  200. + int hh1, mm1, ss1, ms1;
  201. + int hh2, mm2, ss2, ms2;
  202. + int len=0;
  203. + if (sscanf(*buf, "%2d:%2d:%2d:%2d , %2d:%2d:%2d:%2d , %n",
  204. + &hh1, &mm1, &ss1, &ms1,
  205. + &hh2, &mm2, &ss2, &ms2, &len) >= 8 && len>0) {
  206. + int64_t start = (hh1*3600LL + mm1*60LL + ss1) * 100LL + ms1;
  207. + int64_t end = (hh2*3600LL + mm2*60LL + ss2) * 100LL + ms2;
  208. + *duration = end - start;
  209. + *buf+=len;
  210. + return start;
  211. + }
  212. + return AV_NOPTS_VALUE;
  213. +}
  214. +
  215. +static int stl_read_header(AVFormatContext *s)
  216. +{
  217. + STLContext *stl = s->priv_data;
  218. + AVStream *st = avformat_new_stream(s, NULL);
  219. +
  220. + if (!st)
  221. + return AVERROR(ENOMEM);
  222. + avpriv_set_pts_info(st, 64, 1, 100);
  223. + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
  224. + st->codec->codec_id = AV_CODEC_ID_STL;
  225. +
  226. + while (!avio_feof(s->pb)) {
  227. + char line[4096];
  228. + char *p = line;
  229. + const int64_t pos = avio_tell(s->pb);
  230. + int len = ff_get_line(s->pb, line, sizeof(line));
  231. + int64_t pts_start;
  232. + int duration;
  233. + if (!len)
  234. + break;
  235. +
  236. + line[strcspn(line, "\r\n")] = 0;
  237. +
  238. + pts_start = get_pts(&p , &duration);
  239. + if (pts_start != AV_NOPTS_VALUE) {
  240. + AVPacket *sub;
  241. +
  242. + sub = ff_subtitles_queue_insert(&stl->q, p, strlen(p), 0);
  243. + if (!sub)
  244. + return AVERROR(ENOMEM);
  245. + sub->pos = pos;
  246. + sub->pts = pts_start;
  247. + sub->duration = duration;
  248. + }
  249. + }
  250. +
  251. + ff_subtitles_queue_finalize(&stl->q);
  252. + return 0;
  253. +
  254. +}
  255. +static int stl_read_packet(AVFormatContext *s, AVPacket *pkt)
  256. +{
  257. + STLContext *stl = s->priv_data;
  258. + return ff_subtitles_queue_read_packet(&stl->q, pkt);
  259. +}
  260. +
  261. +static int stl_read_seek(AVFormatContext *s, int stream_index,
  262. + int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
  263. +{
  264. + STLContext *stl = s->priv_data;
  265. + return ff_subtitles_queue_seek(&stl->q, s, stream_index,
  266. + min_ts, ts, max_ts, flags);
  267. +}
  268. +
  269. +static int stl_read_close(AVFormatContext *s)
  270. +{
  271. + STLContext *stl = s->priv_data;
  272. + ff_subtitles_queue_clean(&stl->q);
  273. + return 0;
  274. +}
  275. +
  276. +AVInputFormat ff_stl_demuxer = {
  277. + .name = "stl",
  278. + .long_name = NULL_IF_CONFIG_SMALL("Spruce subtitle format"),
  279. + .priv_data_size = sizeof(STLContext),
  280. + .read_probe = stl_probe,
  281. + .read_header = stl_read_header,
  282. + .read_packet = stl_read_packet,
  283. + .read_seek2 = stl_read_seek,
  284. + .read_close = stl_read_close,
  285. + .extensions = "stl",
  286. +};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement