Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.65 KB | None | 0 0
  1. commit 8e52e49146c123b5814ef4abb822842a3aa0869f
  2. Author: Eejya <singh.eejya@gmail.com>
  3. Date: Fri Oct 3 01:43:20 2014 +0530
  4.  
  5. WIP
  6.  
  7. diff --git a/libavformat/Makefile b/libavformat/Makefile
  8. index 86064ea..60e056d 100644
  9. --- a/libavformat/Makefile
  10. +++ b/libavformat/Makefile
  11. @@ -433,6 +433,7 @@ OBJS-$(CONFIG_VOBSUB_DEMUXER) += subtitles.o # mpeg demuxer is in the
  12. OBJS-$(CONFIG_VOC_DEMUXER) += vocdec.o voc.o
  13. OBJS-$(CONFIG_VOC_MUXER) += vocenc.o voc.o
  14. OBJS-$(CONFIG_VPLAYER_DEMUXER) += vplayerdec.o subtitles.o
  15. +OBJS-$(CONFIG_STL_DEMUXER) += stldec.o subtitles.o
  16. OBJS-$(CONFIG_VQF_DEMUXER) += vqf.o
  17. OBJS-$(CONFIG_W64_DEMUXER) += wavdec.o w64.o pcm.o
  18. OBJS-$(CONFIG_W64_MUXER) += wavenc.o w64.o
  19. diff --git a/libavformat/allformats.c b/libavformat/allformats.c
  20. index d54ed9b..c1a3a4e 100644
  21. --- a/libavformat/allformats.c
  22. +++ b/libavformat/allformats.c
  23. @@ -258,6 +258,7 @@ void av_register_all(void)
  24. REGISTER_DEMUXER (SBG, sbg);
  25. REGISTER_DEMUXER (SDP, sdp);
  26. REGISTER_DEMUXER (SDR2, sdr2);
  27. + REGISTER_DEMUXER (STL, stl);
  28. #if CONFIG_RTPDEC
  29. ff_register_rtp_dynamic_payload_handlers();
  30. ff_register_rdt_dynamic_payload_handlers();
  31. diff --git a/libavformat/stldec.c b/libavformat/stldec.c
  32. new file mode 100644
  33. index 0000000..24ae5bd
  34. --- /dev/null
  35. +++ b/libavformat/stldec.c
  36. @@ -0,0 +1,171 @@
  37. +#include "avformat.h"
  38. +#include "internal.h"
  39. +#include "subtitles.h"
  40. +#include "libavutil/bprint.h"
  41. +#include "libavutil/intreadwrite.h"
  42. +
  43. +typedef struct {
  44. + FFDemuxSubtitlesQueue q;
  45. +} STLContext;
  46. +
  47. +static int stl_probe(AVProbeData *p)
  48. +{
  49. + char c;
  50. + const unsigned char *ptr = p->buf;
  51. + if (sscanf(ptr, "%*d:%*d:%*d:%*d , %*d:%*d:%*d:%*d ,", &c) == 1)
  52. + return AVPROBE_SCORE_MAX;
  53. + return 0;
  54. +}
  55. +static int64_t get_pts(const char **buf, int *duration,
  56. + int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2)
  57. +{
  58. + int hh1, mm1, ss1, ms1;
  59. + int hh2, mm2, ss2, ms2;
  60. + if (sscanf(*buf, "%2d:%2d:%2d:%2d , %2d:%2d:%2d:%2d , ",
  61. + &hh1, &mm1, &ss1, &ms1,
  62. + &hh2, &mm2, &ss2, &ms2) >= 6) {
  63. + int64_t start = (hh1*3600LL + mm1*60LL + ss1) * 100LL + ms1;
  64. + int64_t end = (hh2*3600LL + mm2*60LL + ss2) * 100LL + ms2;
  65. + *duration = end - start;
  66. + *buf += ff_subtitles_next_line(*buf);
  67. + return start;
  68. + }
  69. + *buf += ff_subtitles_next_line(*buf);
  70. +
  71. + return AV_NOPTS_VALUE;
  72. +}
  73. +
  74. +static int stl_read_header(AVFormatContext *s)
  75. +{
  76. + STLContext *stl = s->priv_data;
  77. + AVBPrint buf;
  78. + AVStream *st = avformat_new_stream(s, NULL);
  79. + int res = 0;
  80. + FFTextReader tr;
  81. + ff_text_init_avio(&tr, s->pb);
  82. +
  83. + if (!st)
  84. + return AVERROR(ENOMEM);
  85. + avpriv_set_pts_info(st, 64, 1, 100);
  86. + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
  87. + st->codec->codec_id = AV_CODEC_ID_TEXT;
  88. +
  89. + av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
  90. +
  91. + while (!ff_text_eof(&tr)) {
  92. + ff_subtitles_read_text_chunk(&tr, &buf);
  93. +
  94. + if (buf.len) {
  95. + int64_t pos = ff_text_pos(&tr);
  96. + int64_t pts;
  97. + int duration;
  98. + const char *ptr = buf.str;
  99. + int32_t x1 = -1, y1 = -1, x2 = -1, y2 = -1;
  100. + AVPacket *sub;
  101. +
  102. + pts = get_pts(&ptr, &duration, &x1, &y1, &x2, &y2);
  103. + if (pts != AV_NOPTS_VALUE) {
  104. + int len = buf.len - (ptr - buf.str);
  105. + if (len <= 0)
  106. + continue;
  107. + sub = ff_subtitles_queue_insert(&stl->q, ptr, len, 0);
  108. + if (!sub) {
  109. + res = AVERROR(ENOMEM);
  110. + goto end;
  111. + }
  112. + sub->pos = pos;
  113. + sub->pts = pts;
  114. + sub->duration = duration;
  115. + if (x1 != -1) {
  116. + uint8_t *p = av_packet_new_side_data(sub, AV_PKT_DATA_SUBTITLE_POSITION, 16);
  117. + if (p) {
  118. + AV_WL32(p, x1);
  119. + AV_WL32(p + 4, y1);
  120. + AV_WL32(p + 8, x2);
  121. + AV_WL32(p + 12, y2);
  122. + }
  123. + }
  124. + }
  125. + }
  126. + }
  127. +
  128. + ff_subtitles_queue_finalize(&stl->q);
  129. +
  130. +end:
  131. + av_bprint_finalize(&buf, NULL);
  132. + return res;
  133. +}
  134. +
  135. +/*static int stl_read_header(AVFormatContext *s)
  136. +{
  137. + STLContext *stl = s->priv_data;
  138. + AVStream *st = avformat_new_stream(s, NULL);
  139. +
  140. + if (!st)
  141. + return AVERROR(ENOMEM);
  142. + avpriv_set_pts_info(st, 64, 1, 100);
  143. + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
  144. + st->codec->codec_id = AV_CODEC_ID_TEXT;
  145. +
  146. + while (!avio_feof(s->pb)) {
  147. + char line[4096];
  148. + char *p = line;
  149. +
  150. + const int64_t pos = avio_tell(s->pb);
  151. + int len = ff_get_line(s->pb, line, sizeof(line));
  152. + int64_t pts_start;
  153. +
  154. + if (!len)
  155. + break;
  156. +
  157. + line[strcspn(line, "\r\n")] = 0;
  158. +
  159. + pts_start = read_ts(&p);
  160. + if (pts_start != AV_NOPTS_VALUE) {
  161. + AVPacket *sub;
  162. +
  163. + sub = ff_subtitles_queue_insert(&stl->q, p, strlen(p), 0);
  164. + if (!sub)
  165. + return AVERROR(ENOMEM);
  166. + sub->pos = pos;
  167. + sub->pts = pts_start;
  168. + sub->duration = -1;
  169. + }
  170. + }
  171. +
  172. + ff_subtitles_queue_finalize(&stl->q);
  173. + return 0;
  174. +}
  175. +*/
  176. +static int stl_read_packet(AVFormatContext *s, AVPacket *pkt)
  177. +{
  178. + STLContext *stl = s->priv_data;
  179. + return ff_subtitles_queue_read_packet(&stl->q, pkt);
  180. +}
  181. +
  182. +static int stl_read_seek(AVFormatContext *s, int stream_index,
  183. + int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
  184. +{
  185. + STLContext *stl = s->priv_data;
  186. + return ff_subtitles_queue_seek(&stl->q, s, stream_index,
  187. + min_ts, ts, max_ts, flags);
  188. +}
  189. +
  190. +static int stl_read_close(AVFormatContext *s)
  191. +{
  192. + STLContext *stl = s->priv_data;
  193. + ff_subtitles_queue_clean(&stl->q);
  194. + return 0;
  195. +}
  196. +
  197. +AVInputFormat ff_stl_demuxer = {
  198. + .name = "stl",
  199. + .long_name = NULL_IF_CONFIG_SMALL("STL subtitles"),
  200. + .priv_data_size = sizeof(STLContext),
  201. + .read_probe = stl_probe,
  202. + .read_header = stl_read_header,
  203. + .read_packet = stl_read_packet,
  204. + .read_seek2 = stl_read_seek,
  205. + .read_close = stl_read_close,
  206. + .extensions = "stl",
  207. +};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement