Advertisement
svenhoefer

Untitled

Dec 29th, 2017
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. void cFileParser::GetAllSubs(uint16_t *pids, unsigned short *supported, uint16_t *numpida, std::string *language)
  2. {
  3.     (*numpida) = 0;
  4.  
  5.     if(pFormatCtx == NULL)
  6.         return;
  7.  
  8.     for (u_int32 uCount = 0; uCount < pFormatCtx->nb_streams ; uCount++) {
  9.         AVStream *st            = pFormatCtx->streams[uCount];
  10.  
  11. #if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT( 57,25,101 ))
  12.         AVCodecContext *codec   = st->codec;
  13. #else
  14.         AVCodecParameters *codec = st->codecpar;
  15. #endif
  16.         if (codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
  17.             pids[(*numpida)] = uCount;
  18.             supported[(*numpida)] = 0;
  19.             AVCodec * avcodec = avcodec_find_decoder(codec->codec_id);
  20.             //if (codec->codec)
  21.             if (avcodec)
  22.                 supported[(*numpida)] = 1;
  23.  
  24.             language[(*numpida)].clear();
  25.             AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
  26.             if (lang) {
  27.                 language[(*numpida)] += lang->value;
  28.             }
  29.             AVDictionaryEntry *title = av_dict_get(st->metadata, "title", NULL, 0);
  30.             if (title) {
  31.                 language[(*numpida)] += " ";
  32.                 language[(*numpida)] += title->value;
  33.             }
  34.             (*numpida)++;
  35.             if((*numpida) == MAX_PLAYBACK_PIDS)//max pids in movieplayer
  36.                 break;
  37.         }
  38.     }
  39.     if (pSubCtx && pSubCtx->nb_streams && (*numpida) < MAX_PLAYBACK_PIDS) {
  40.         AVStream *st = pSubCtx->streams[0];
  41. #if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT( 57,25,101 ))
  42.         AVCodecContext *codec   = st->codec;
  43. #else
  44.         AVCodecParameters *codec = st->codecpar;
  45. #endif
  46.         language[(*numpida)] = "external";
  47.         pids[(*numpida)] = EXTERNAL_SUBT_PID;
  48.         AVCodec * avcodec = avcodec_find_decoder(codec->codec_id);
  49.         //if (codec->codec)
  50.         if (avcodec)
  51.             supported[(*numpida)] = 1;
  52.  
  53.         (*numpida)++;
  54.     }
  55. }
  56.  
  57. void cFileParser::SetSubtitles(int pid, std::string charset)
  58. {
  59.     PRINTF("SetSubtitles: %d\n", pid);
  60.  
  61.     if (pFormatCtx == NULL)
  62.         return;
  63.  
  64.     subsWriter.SetCharset(charset);
  65.     PauseReadWrite();
  66.     if (!SendCommand(PARSER_CMD_CHANGE_SUBT_STREAM, pid))
  67.         PRINTF("%d: SendCommand error\n", __LINE__);
  68.     if (!SendCommand(PARSER_CMD_START_READER))
  69.         PRINTF("%d: SendCommand error\n", __LINE__);
  70. }
  71.  
  72. void cFileParser::GetChapters(std::vector<int> &positions, std::vector<std::string> &titles)
  73. {
  74.     positions.clear();
  75.     titles.clear();
  76.  
  77.     if(pFormatCtx == NULL)
  78.         return;
  79.     if (is_bd) {
  80.         bd.GetChapters(positions, titles);
  81.         return;
  82.     }
  83.     for (unsigned i = 0; i < pFormatCtx->nb_chapters; i++) {
  84.         AVChapter *ch = pFormatCtx->chapters[i];
  85.         AVDictionaryEntry *title = av_dict_get(ch->metadata, "title", NULL, 0);
  86.         FDPRINTF("start %f end %f title [%s]\n", ch->start * av_q2d(ch->time_base), ch->end * av_q2d(ch->time_base), title ? title->value : "");
  87.         int chstart = ch->start * av_q2d(ch->time_base);
  88.         int chend = ch->end * av_q2d(ch->time_base);
  89.         char str[256];
  90.         if (title)
  91.             snprintf(str, sizeof(str), "%s (%d - %d)", title->value, chstart, chend);
  92.         else
  93.             snprintf(str, sizeof(str), "%d (%d - %d)", i+1, chstart, chend);
  94.         chstart = (double) 1000 * ch->start * av_q2d(ch->time_base);
  95.         positions.push_back(chstart);
  96.         titles.push_back(std::string(str));
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement