Advertisement
Guest User

Untitled

a guest
Oct 4th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. diff --git a/libavformat/stldec.c b/libavformat/stldec.c
  2. index 24ae5bd..d841e1e 100644
  3. --- a/libavformat/stldec.c
  4. +++ b/libavformat/stldec.c
  5. @@ -1,7 +1,6 @@
  6. #include "avformat.h"
  7. #include "internal.h"
  8. #include "subtitles.h"
  9. -#include "libavutil/bprint.h"
  10. #include "libavutil/intreadwrite.h"
  11.  
  12. typedef struct {
  13. @@ -10,97 +9,35 @@ typedef struct {
  14.  
  15. static int stl_probe(AVProbeData *p)
  16. {
  17. - char c;
  18. +
  19. const unsigned char *ptr = p->buf;
  20. - if (sscanf(ptr, "%*d:%*d:%*d:%*d , %*d:%*d:%*d:%*d ,", &c) == 1)
  21. + if (sscanf(ptr, "%*d:%*d:%*d:%*d , %*d:%*d:%*d:%*d ,") == 1)
  22. return AVPROBE_SCORE_MAX;
  23. return 0;
  24. }
  25. -static int64_t get_pts(const char **buf, int *duration,
  26. - int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2)
  27. +static int64_t get_pts(char **buf, int *duration)
  28. {
  29. int hh1, mm1, ss1, ms1;
  30. int hh2, mm2, ss2, ms2;
  31. - if (sscanf(*buf, "%2d:%2d:%2d:%2d , %2d:%2d:%2d:%2d , ",
  32. + int len;
  33. + if (sscanf(*buf, "%2d:%2d:%2d:%2d , %2d:%2d:%2d:%2d , %n",
  34. &hh1, &mm1, &ss1, &ms1,
  35. - &hh2, &mm2, &ss2, &ms2) >= 6) {
  36. + &hh2, &mm2, &ss2, &ms2, &len) >= 6) {
  37. +
  38. int64_t start = (hh1*3600LL + mm1*60LL + ss1) * 100LL + ms1;
  39. int64_t end = (hh2*3600LL + mm2*60LL + ss2) * 100LL + ms2;
  40. *duration = end - start;
  41. - *buf += ff_subtitles_next_line(*buf);
  42. + *buf+=len;
  43. return start;
  44. - }
  45. - *buf += ff_subtitles_next_line(*buf);
  46. -
  47. - return AV_NOPTS_VALUE;
  48. + }
  49. + return AV_NOPTS_VALUE;
  50. }
  51.  
  52. static int stl_read_header(AVFormatContext *s)
  53. {
  54. STLContext *stl = s->priv_data;
  55. - AVBPrint buf;
  56. AVStream *st = avformat_new_stream(s, NULL);
  57. - int res = 0;
  58. - FFTextReader tr;
  59. - ff_text_init_avio(&tr, s->pb);
  60. -
  61. - if (!st)
  62. - return AVERROR(ENOMEM);
  63. - avpriv_set_pts_info(st, 64, 1, 100);
  64. - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
  65. - st->codec->codec_id = AV_CODEC_ID_TEXT;
  66. -
  67. - av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
  68. -
  69. - while (!ff_text_eof(&tr)) {
  70. - ff_subtitles_read_text_chunk(&tr, &buf);
  71. -
  72. - if (buf.len) {
  73. - int64_t pos = ff_text_pos(&tr);
  74. - int64_t pts;
  75. - int duration;
  76. - const char *ptr = buf.str;
  77. - int32_t x1 = -1, y1 = -1, x2 = -1, y2 = -1;
  78. - AVPacket *sub;
  79.  
  80. - pts = get_pts(&ptr, &duration, &x1, &y1, &x2, &y2);
  81. - if (pts != AV_NOPTS_VALUE) {
  82. - int len = buf.len - (ptr - buf.str);
  83. - if (len <= 0)
  84. - continue;
  85. - sub = ff_subtitles_queue_insert(&stl->q, ptr, len, 0);
  86. - if (!sub) {
  87. - res = AVERROR(ENOMEM);
  88. - goto end;
  89. - }
  90. - sub->pos = pos;
  91. - sub->pts = pts;
  92. - sub->duration = duration;
  93. - if (x1 != -1) {
  94. - uint8_t *p = av_packet_new_side_data(sub, AV_PKT_DATA_SUBTITLE_POSITION, 16);
  95. - if (p) {
  96. - AV_WL32(p, x1);
  97. - AV_WL32(p + 4, y1);
  98. - AV_WL32(p + 8, x2);
  99. - AV_WL32(p + 12, y2);
  100. - }
  101. - }
  102. - }
  103. - }
  104. - }
  105. -
  106. - ff_subtitles_queue_finalize(&stl->q);
  107. -
  108. -end:
  109. - av_bprint_finalize(&buf, NULL);
  110. - return res;
  111. -}
  112. -
  113. -/*static int stl_read_header(AVFormatContext *s)
  114. -{
  115. - STLContext *stl = s->priv_data;
  116. - AVStream *st = avformat_new_stream(s, NULL);
  117. -
  118. if (!st)
  119. return AVERROR(ENOMEM);
  120. avpriv_set_pts_info(st, 64, 1, 100);
  121. @@ -110,17 +47,16 @@ end:
  122. while (!avio_feof(s->pb)) {
  123. char line[4096];
  124. char *p = line;
  125. -
  126. const int64_t pos = avio_tell(s->pb);
  127. int len = ff_get_line(s->pb, line, sizeof(line));
  128. int64_t pts_start;
  129. -
  130. + int duration;
  131. if (!len)
  132. break;
  133.  
  134. line[strcspn(line, "\r\n")] = 0;
  135.  
  136. - pts_start = read_ts(&p);
  137. + pts_start = get_pts(&p , &duration);
  138. if (pts_start != AV_NOPTS_VALUE) {
  139. AVPacket *sub;
  140.  
  141. @@ -129,14 +65,14 @@ end:
  142. return AVERROR(ENOMEM);
  143. sub->pos = pos;
  144. sub->pts = pts_start;
  145. - sub->duration = -1;
  146. + sub->duration = duration;
  147. }
  148. }
  149.  
  150. ff_subtitles_queue_finalize(&stl->q);
  151. return 0;
  152. +
  153. }
  154. -*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement