Advertisement
Guest User

Untitled

a guest
Oct 4th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. commit 713f8568fecc808caf663c1d7097de52d95db59d
  2. Author: Eejya <singh.eejya@gmail.com>
  3. Date: Fri Oct 3 01:43:20 2014 +0530
  4.  
  5. Added STL demuxer and made changes to get a proper format.
  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..d841e1e
  34. --- /dev/null
  35. +++ b/libavformat/stldec.c
  36. @@ -0,0 +1,107 @@
  37. +#include "avformat.h"
  38. +#include "internal.h"
  39. +#include "subtitles.h"
  40. +#include "libavutil/intreadwrite.h"
  41. +
  42. +typedef struct {
  43. + FFDemuxSubtitlesQueue q;
  44. +} STLContext;
  45. +
  46. +static int stl_probe(AVProbeData *p)
  47. +{
  48. +
  49. + const unsigned char *ptr = p->buf;
  50. + if (sscanf(ptr, "%*d:%*d:%*d:%*d , %*d:%*d:%*d:%*d ,") == 1)
  51. + return AVPROBE_SCORE_MAX;
  52. + return 0;
  53. +}
  54. +static int64_t get_pts(char **buf, int *duration)
  55. +{
  56. + int hh1, mm1, ss1, ms1;
  57. + int hh2, mm2, ss2, ms2;
  58. + int len;
  59. + if (sscanf(*buf, "%2d:%2d:%2d:%2d , %2d:%2d:%2d:%2d , %n",
  60. + &hh1, &mm1, &ss1, &ms1,
  61. + &hh2, &mm2, &ss2, &ms2, &len) >= 6) {
  62. +
  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+=len;
  67. + return start;
  68. + }
  69. + return AV_NOPTS_VALUE;
  70. +}
  71. +
  72. +static int stl_read_header(AVFormatContext *s)
  73. +{
  74. + STLContext *stl = s->priv_data;
  75. + AVStream *st = avformat_new_stream(s, NULL);
  76. +
  77. + if (!st)
  78. + return AVERROR(ENOMEM);
  79. + avpriv_set_pts_info(st, 64, 1, 100);
  80. + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
  81. + st->codec->codec_id = AV_CODEC_ID_TEXT;
  82. +
  83. + while (!avio_feof(s->pb)) {
  84. + char line[4096];
  85. + char *p = line;
  86. + const int64_t pos = avio_tell(s->pb);
  87. + int len = ff_get_line(s->pb, line, sizeof(line));
  88. + int64_t pts_start;
  89. + int duration;
  90. + if (!len)
  91. + break;
  92. +
  93. + line[strcspn(line, "\r\n")] = 0;
  94. +
  95. + pts_start = get_pts(&p , &duration);
  96. + if (pts_start != AV_NOPTS_VALUE) {
  97. + AVPacket *sub;
  98. +
  99. + sub = ff_subtitles_queue_insert(&stl->q, p, strlen(p), 0);
  100. + if (!sub)
  101. + return AVERROR(ENOMEM);
  102. + sub->pos = pos;
  103. + sub->pts = pts_start;
  104. + sub->duration = duration;
  105. + }
  106. + }
  107. +
  108. + ff_subtitles_queue_finalize(&stl->q);
  109. + return 0;
  110. +
  111. +}
  112. +static int stl_read_packet(AVFormatContext *s, AVPacket *pkt)
  113. +{
  114. + STLContext *stl = s->priv_data;
  115. + return ff_subtitles_queue_read_packet(&stl->q, pkt);
  116. +}
  117. +
  118. +static int stl_read_seek(AVFormatContext *s, int stream_index,
  119. + int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
  120. +{
  121. + STLContext *stl = s->priv_data;
  122. + return ff_subtitles_queue_seek(&stl->q, s, stream_index,
  123. + min_ts, ts, max_ts, flags);
  124. +}
  125. +
  126. +static int stl_read_close(AVFormatContext *s)
  127. +{
  128. + STLContext *stl = s->priv_data;
  129. + ff_subtitles_queue_clean(&stl->q);
  130. + return 0;
  131. +}
  132. +
  133. +AVInputFormat ff_stl_demuxer = {
  134. + .name = "stl",
  135. + .long_name = NULL_IF_CONFIG_SMALL("STL subtitles"),
  136. + .priv_data_size = sizeof(STLContext),
  137. + .read_probe = stl_probe,
  138. + .read_header = stl_read_header,
  139. + .read_packet = stl_read_packet,
  140. + .read_seek2 = stl_read_seek,
  141. + .read_close = stl_read_close,
  142. + .extensions = "stl",
  143. +};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement