Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void cFileParser::GetAllSubs(uint16_t *pids, unsigned short *supported, uint16_t *numpida, std::string *language)
- {
- (*numpida) = 0;
- if(pFormatCtx == NULL)
- return;
- for (u_int32 uCount = 0; uCount < pFormatCtx->nb_streams ; uCount++) {
- AVStream *st = pFormatCtx->streams[uCount];
- #if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT( 57,25,101 ))
- AVCodecContext *codec = st->codec;
- #else
- AVCodecParameters *codec = st->codecpar;
- #endif
- if (codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
- pids[(*numpida)] = uCount;
- supported[(*numpida)] = 0;
- AVCodec * avcodec = avcodec_find_decoder(codec->codec_id);
- //if (codec->codec)
- if (avcodec)
- supported[(*numpida)] = 1;
- language[(*numpida)].clear();
- AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
- if (lang) {
- language[(*numpida)] += lang->value;
- }
- AVDictionaryEntry *title = av_dict_get(st->metadata, "title", NULL, 0);
- if (title) {
- language[(*numpida)] += " ";
- language[(*numpida)] += title->value;
- }
- (*numpida)++;
- if((*numpida) == MAX_PLAYBACK_PIDS)//max pids in movieplayer
- break;
- }
- }
- if (pSubCtx && pSubCtx->nb_streams && (*numpida) < MAX_PLAYBACK_PIDS) {
- AVStream *st = pSubCtx->streams[0];
- #if (LIBAVFORMAT_VERSION_INT < AV_VERSION_INT( 57,25,101 ))
- AVCodecContext *codec = st->codec;
- #else
- AVCodecParameters *codec = st->codecpar;
- #endif
- language[(*numpida)] = "external";
- pids[(*numpida)] = EXTERNAL_SUBT_PID;
- AVCodec * avcodec = avcodec_find_decoder(codec->codec_id);
- //if (codec->codec)
- if (avcodec)
- supported[(*numpida)] = 1;
- (*numpida)++;
- }
- }
- void cFileParser::SetSubtitles(int pid, std::string charset)
- {
- PRINTF("SetSubtitles: %d\n", pid);
- if (pFormatCtx == NULL)
- return;
- subsWriter.SetCharset(charset);
- PauseReadWrite();
- if (!SendCommand(PARSER_CMD_CHANGE_SUBT_STREAM, pid))
- PRINTF("%d: SendCommand error\n", __LINE__);
- if (!SendCommand(PARSER_CMD_START_READER))
- PRINTF("%d: SendCommand error\n", __LINE__);
- }
- void cFileParser::GetChapters(std::vector<int> &positions, std::vector<std::string> &titles)
- {
- positions.clear();
- titles.clear();
- if(pFormatCtx == NULL)
- return;
- if (is_bd) {
- bd.GetChapters(positions, titles);
- return;
- }
- for (unsigned i = 0; i < pFormatCtx->nb_chapters; i++) {
- AVChapter *ch = pFormatCtx->chapters[i];
- AVDictionaryEntry *title = av_dict_get(ch->metadata, "title", NULL, 0);
- 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 : "");
- int chstart = ch->start * av_q2d(ch->time_base);
- int chend = ch->end * av_q2d(ch->time_base);
- char str[256];
- if (title)
- snprintf(str, sizeof(str), "%s (%d - %d)", title->value, chstart, chend);
- else
- snprintf(str, sizeof(str), "%d (%d - %d)", i+1, chstart, chend);
- chstart = (double) 1000 * ch->start * av_q2d(ch->time_base);
- positions.push_back(chstart);
- titles.push_back(std::string(str));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement