Advertisement
Guest User

Untitled

a guest
Oct 13th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. commit 9071bab8fa6f9d920cfa1044fb12897eeba67bc2
  2. Author: Eejya <singh.eejya@gmail.com>
  3. Date: Mon Oct 13 22:49:03 2014 +0530
  4.  
  5. Added STL demuxer for supporting .stl files
  6.  
  7. diff --git a/doc/general.texi b/doc/general.texi
  8. index 2252f7b..ff74c61 100644
  9. --- a/doc/general.texi
  10. +++ b/doc/general.texi
  11. @@ -1032,6 +1032,7 @@ performance on systems without hardware floating point support).
  12. @item RealText @tab @tab X @tab @tab X
  13. @item SAMI @tab @tab X @tab @tab X
  14. @item SSA/ASS @tab X @tab X @tab X @tab X
  15. +@item STL @tab @tab X @tab @tab
  16. @item SubRip (SRT) @tab X @tab X @tab X @tab X
  17. @item SubViewer v1 @tab @tab X @tab @tab X
  18. @item SubViewer @tab @tab X @tab @tab X
  19. diff --git a/libavformat/Makefile b/libavformat/Makefile
  20. index 86064ea..60e056d 100644
  21. --- a/libavformat/Makefile
  22. +++ b/libavformat/Makefile
  23. @@ -433,6 +433,7 @@ OBJS-$(CONFIG_VOBSUB_DEMUXER) += subtitles.o # mpeg demuxer is in the
  24. OBJS-$(CONFIG_VOC_DEMUXER) += vocdec.o voc.o
  25. OBJS-$(CONFIG_VOC_MUXER) += vocenc.o voc.o
  26. OBJS-$(CONFIG_VPLAYER_DEMUXER) += vplayerdec.o subtitles.o
  27. +OBJS-$(CONFIG_STL_DEMUXER) += stldec.o subtitles.o
  28. OBJS-$(CONFIG_VQF_DEMUXER) += vqf.o
  29. OBJS-$(CONFIG_W64_DEMUXER) += wavdec.o w64.o pcm.o
  30. OBJS-$(CONFIG_W64_MUXER) += wavenc.o w64.o
  31. diff --git a/libavformat/allformats.c b/libavformat/allformats.c
  32. index d54ed9b..c1a3a4e 100644
  33. --- a/libavformat/allformats.c
  34. +++ b/libavformat/allformats.c
  35. @@ -258,6 +258,7 @@ void av_register_all(void)
  36. REGISTER_DEMUXER (SBG, sbg);
  37. REGISTER_DEMUXER (SDP, sdp);
  38. REGISTER_DEMUXER (SDR2, sdr2);
  39. + REGISTER_DEMUXER (STL, stl);
  40. #if CONFIG_RTPDEC
  41. ff_register_rtp_dynamic_payload_handlers();
  42. ff_register_rdt_dynamic_payload_handlers();
  43. diff --git a/libavformat/stldec.c b/libavformat/stldec.c
  44. new file mode 100644
  45. index 0000000..bec1ed1
  46. --- /dev/null
  47. +++ b/libavformat/stldec.c
  48. @@ -0,0 +1,132 @@
  49. +/*
  50. + * Copyright (c) 2012 Clément Bœsch
  51. + *
  52. + * This file is part of FFmpeg.
  53. + *
  54. + * FFmpeg is free software; you can redistribute it and/or
  55. + * modify it under the terms of the GNU Lesser General Public
  56. + * License as published by the Free Software Foundation; either
  57. + * version 2.1 of the License, or (at your option) any later version.
  58. + *
  59. + * FFmpeg is distributed in the hope that it will be useful,
  60. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  61. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  62. + * Lesser General Public License for more details.
  63. + *
  64. + * You should have received a copy of the GNU Lesser General Public
  65. + * License along with FFmpeg; if not, write to the Free Software
  66. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  67. + */
  68. +
  69. +/**
  70. + * @file
  71. + * STL subtitles format demuxer
  72. + */
  73. +#include "avformat.h"
  74. +#include "internal.h"
  75. +#include "subtitles.h"
  76. +#include "libavutil/intreadwrite.h"
  77. +typedef struct {
  78. + FFDemuxSubtitlesQueue q;
  79. +} STLContext;
  80. +
  81. +static int stl_probe(AVProbeData *p)
  82. +{
  83. + char c;
  84. + const unsigned char *ptr = p->buf;
  85. + while(*ptr=='\r' || *ptr=='\n' || *ptr=='$' || (ptr[0]=='/' && ptr[1]=='/'))
  86. + ptr+=ff_subtitles_next_line(ptr);
  87. + if (sscanf(ptr, "%*d:%*d:%*d:%*d , %*d:%*d:%*d:%*d , %c", &c) == 1)
  88. + return AVPROBE_SCORE_MAX;
  89. + return 0;
  90. +
  91. +}
  92. +static int64_t get_pts(char **buf, int *duration)
  93. +{
  94. + int hh1, mm1, ss1, ms1;
  95. + int hh2, mm2, ss2, ms2;
  96. + int len=0;
  97. + if (sscanf(*buf, "%2d:%2d:%2d:%2d , %2d:%2d:%2d:%2d , %n",
  98. + &hh1, &mm1, &ss1, &ms1,
  99. + &hh2, &mm2, &ss2, &ms2, &len) >= 8 && len>0) {
  100. + int64_t start = (hh1*3600LL + mm1*60LL + ss1) * 100LL + ms1;
  101. + int64_t end = (hh2*3600LL + mm2*60LL + ss2) * 100LL + ms2;
  102. + *duration = end - start;
  103. + *buf+=len;
  104. + return start;
  105. + }
  106. + return AV_NOPTS_VALUE;
  107. +}
  108. +
  109. +static int stl_read_header(AVFormatContext *s)
  110. +{
  111. + STLContext *stl = s->priv_data;
  112. + AVStream *st = avformat_new_stream(s, NULL);
  113. +
  114. + if (!st)
  115. + return AVERROR(ENOMEM);
  116. + avpriv_set_pts_info(st, 64, 1, 100);
  117. + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
  118. + st->codec->codec_id = AV_CODEC_ID_TEXT;
  119. +
  120. + while (!avio_feof(s->pb)) {
  121. + char line[4096];
  122. + char *p = line;
  123. + const int64_t pos = avio_tell(s->pb);
  124. + int len = ff_get_line(s->pb, line, sizeof(line));
  125. + int64_t pts_start;
  126. + int duration;
  127. + if (!len)
  128. + break;
  129. +
  130. + line[strcspn(line, "\r\n")] = 0;
  131. +
  132. + pts_start = get_pts(&p , &duration);
  133. + if (pts_start != AV_NOPTS_VALUE) {
  134. + AVPacket *sub;
  135. +
  136. + sub = ff_subtitles_queue_insert(&stl->q, p, strlen(p), 0);
  137. + if (!sub)
  138. + return AVERROR(ENOMEM);
  139. + sub->pos = pos;
  140. + sub->pts = pts_start;
  141. + sub->duration = duration;
  142. + }
  143. + }
  144. +
  145. + ff_subtitles_queue_finalize(&stl->q);
  146. + return 0;
  147. +
  148. +}
  149. +static int stl_read_packet(AVFormatContext *s, AVPacket *pkt)
  150. +{
  151. + STLContext *stl = s->priv_data;
  152. + return ff_subtitles_queue_read_packet(&stl->q, pkt);
  153. +}
  154. +
  155. +static int stl_read_seek(AVFormatContext *s, int stream_index,
  156. + int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
  157. +{
  158. + STLContext *stl = s->priv_data;
  159. + return ff_subtitles_queue_seek(&stl->q, s, stream_index,
  160. + min_ts, ts, max_ts, flags);
  161. +}
  162. +
  163. +static int stl_read_close(AVFormatContext *s)
  164. +{
  165. + STLContext *stl = s->priv_data;
  166. + ff_subtitles_queue_clean(&stl->q);
  167. + return 0;
  168. +}
  169. +
  170. +AVInputFormat ff_stl_demuxer = {
  171. + .name = "stl",
  172. + .long_name = NULL_IF_CONFIG_SMALL("STL subtitles"),
  173. + .priv_data_size = sizeof(STLContext),
  174. + .read_probe = stl_probe,
  175. + .read_header = stl_read_header,
  176. + .read_packet = stl_read_packet,
  177. + .read_seek2 = stl_read_seek,
  178. + .read_close = stl_read_close,
  179. + .extensions = "stl",
  180. +};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement