static void avlog_theoraplayer(void* p, int level, const char* fmt, va_list vargs) { th_writelog(fmt); static char logstr[2048]; vsprintf(logstr, fmt, vargs); th_writelog("ffmpeg: " + std::string(logstr)); }
static int readFunction(void* data, uint8_t* buf, int buf_size) { #ifdef _FFMPEG_DEBUG th_writelog("reading " + str(buf_size) + " bytes"); #endif TheoraDataSource* src = (TheoraDataSource*) data; return src->read(buf, buf_size); }
int show_codecs(void *optctx, const char *opt, const char *arg) { const AVCodecDescriptor **codecs; unsigned i, nb_codecs = get_codecs_sorted(&codecs); char tmp[1024]; th_writelog("Codecs:\n" " D..... = Decoding supported\n" " .E.... = Encoding supported\n" " ..V... = Video codec\n" " ..A... = Audio codec\n" " ..S... = Subtitle codec\n" " ...I.. = Intra frame-only codec\n" " ....L. = Lossy compression\n" " .....S = Lossless compression\n" " -------\n"); for (i = 0; i < nb_codecs; ++i) { const AVCodecDescriptor *desc = codecs[i]; const AVCodec *codec = NULL; _log(" "); _log(avcodec_find_decoder(desc->id) ? "D" : "."); _log(avcodec_find_encoder(desc->id) ? "E" : "."); _log(get_media_type_char(desc->type)); _log((desc->props & AV_CODEC_PROP_INTRA_ONLY) ? "I" : "."); _log((desc->props & AV_CODEC_PROP_LOSSY) ? "L" : "."); _log((desc->props & AV_CODEC_PROP_LOSSLESS) ? "S" : "."); sprintf(tmp, " %-20s %s", desc->name, desc->long_name ? desc->long_name : ""); _log(tmp); /* print decoders/encoders when there's more than one or their * names are different from codec name */ while ((codec = next_codec_for_id(desc->id, codec, 0))) { if (strcmp(codec->name, desc->name)) { print_codecs_for_id(desc->id, 0); break; } } codec = NULL; while ((codec = next_codec_for_id(desc->id, codec, 1))) { if (strcmp(codec->name, desc->name)) { print_codecs_for_id(desc->id, 1); break; } } _log("\n"); } av_free(codecs); av_log(0, 0, "%s", text.c_str()); return 0; }
void TheoraVideoManager::destroyVideoClip(TheoraVideoClip* clip) { if (clip) { th_writelog("Destroying video clip: " + clip->getName()); mWorkMutex->lock(); bool reported = 0; while (clip->mAssignedWorkerThread) { if (!reported) { th_writelog(" - Waiting for WorkerThread to finish decoding in order to destroy"); reported = 1; } _psleep(1); } if (reported) th_writelog(" - WorkerThread done, destroying..."); // erase the clip from the clip list foreach (TheoraVideoClip*, mClips) { if ((*it) == clip) { mClips.erase(it); break; } } // remove all it's references from the work log mWorkLog.remove(clip); // delete the actual clip delete clip; #ifdef _DEBUG th_writelog("Destroyed video."); #endif mWorkMutex->unlock(); } }
void TheoraVideoManager::destroyVideoClip(TheoraVideoClip* clip) { if (clip) { th_writelog("Destroying video clip: "+clip->getName()); mWorkMutex->lock(); bool reported=0; while (clip->mAssignedWorkerThread) { if (!reported) { th_writelog("Waiting for WorkerThread to finish decoding in order to destroy"); reported=1; } _psleep(1); } if (reported) th_writelog("WorkerThread done, destroying.."); foreach(TheoraVideoClip*,mClips) if ((*it) == clip) { mClips.erase(it); break; } delete clip; th_writelog("Destroyed video."); mWorkMutex->unlock(); } }
static int64_t seekFunction(void* data, int64_t offset, int whence) { #ifdef _FFMPEG_DEBUG th_writelog("seeking: offset = " + str((long) offset) + ", whence = " + str(whence)); #endif TheoraDataSource* src = (TheoraDataSource*) data; if (whence == AVSEEK_SIZE) return src->size(); else if (whence == SEEK_SET) src->seek((long) offset); else if (whence == SEEK_END) src->seek(src->size() - (long) offset); return src->tell(); }
void TheoraFileDataSource::openFile() { if (mFilePtr == NULL) { mFilePtr=fopen(mFilename.c_str(), "rb"); if (!mFilePtr) { std::string msg = "Can't open video file: " + mFilename; th_writelog(msg); throw TheoraGenericException(msg); } fseek(mFilePtr, 0, SEEK_END); mSize = ftell(mFilePtr); fseek(mFilePtr, 0, SEEK_SET); } }
void TheoraVideoClip_FFmpeg::load(TheoraDataSource* source) { mVideoStreamIndex = -1; mFrameNumber = 0; AVDictionary* optionsDict = NULL; if (!ffmpegInitialised) { #ifdef _FFMPEG_DEBUG th_writelog("Initializing ffmpeg"); #endif th_writelog("avcodec version: " + str(avcodec_version())); av_register_all(); av_log_set_level(AV_LOG_DEBUG); av_log_set_callback(avlog_theoraplayer); ffmpegInitialised = 1; //show_codecs(0, 0, 0); } mInputBuffer = (unsigned char*) av_malloc(READ_BUFFER_SIZE); mAvioContext = avio_alloc_context(mInputBuffer, READ_BUFFER_SIZE, 0, source, &readFunction, NULL, &seekFunction); #ifdef _FFMPEG_DEBUG th_writelog(mName + ": avio context created"); #endif mFormatContext = avformat_alloc_context(); #ifdef _FFMPEG_DEBUG th_writelog(mName + ": avformat context created"); #endif mFormatContext->pb = mAvioContext; int err; if ((err = avformat_open_input(&mFormatContext, "", NULL, NULL)) != 0) { th_writelog(mName + ": avformat input opening failed!"); th_writelog(mName + ": error_code: " + str(err)); return; } #ifdef _FFMPEG_DEBUG th_writelog(mName + ": avformat input opened"); #endif // Retrieve stream information if (avformat_find_stream_info(mFormatContext, NULL) < 0) return; // Couldn't find stream information #ifdef _FFMPEG_DEBUG th_writelog(mName + ": got stream info"); #endif // Dump information about file onto standard error // av_dump_format(mFormatContext, 0, "", 0); // Find the first video stream for (int i = 0; i < mFormatContext->nb_streams; ++i) { if(mFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { mVideoStreamIndex = i; break; } } if (mVideoStreamIndex == -1) return; // Didn't find a video stream #ifdef _FFMPEG_DEBUG th_writelog(mName + ": Found video stream at index " + str(mVideoStreamIndex)); #endif // Get a pointer to the codec context for the video stream mCodecContext = mFormatContext->streams[mVideoStreamIndex]->codec; // Find the decoder for the video stream mCodec = avcodec_find_decoder(mCodecContext->codec_id); if (mCodec == NULL) { th_writelog("Unsupported codec!"); return; // Codec not found } // Open codec if(avcodec_open2(mCodecContext, mCodec, &optionsDict) < 0) return; // Could not open codec #ifdef _FFMPEG_DEBUG th_writelog(mName + ": Codec opened"); #endif mFrame = avcodec_alloc_frame(); #ifdef _FFMPEG_DEBUG th_writelog(mName + ": Frame allocated"); #endif //AVRational rational = mCodecContext->time_base; mFPS = 25; //TODOOOOOO!!! mWidth = mStride = mCodecContext->width; mHeight = mCodecContext->height; mFrameDuration = 1.0f / mFPS; mDuration = mFormatContext->duration / AV_TIME_BASE; if (mFrameQueue == NULL) // todo - why is this set in the backend class? it should be set in the base class, check other backends as well { mFrameQueue = new TheoraFrameQueue(this); mFrameQueue->setSize(mNumPrecachedFrames); } }
void _TheoraGenericException::writeOutput() { th_writelog("----------------\nException Error!\n\n"+repr()+"\n----------------"); }