summaryrefslogtreecommitdiff
path: root/rotord/src/libavwrapper.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2013-09-16 14:31:04 +0100
committerTim Redfern <tim@eclectronics.org>2013-09-16 14:31:04 +0100
commit440ba17594d17736a56cac0d89be97fb63577989 (patch)
treeb3853fbba0a13a481c5c5247114a6a1170d5efb3 /rotord/src/libavwrapper.cpp
parent1b37a3d71dabc451f48f05fce7ce2d300212c43c (diff)
ffmpegsource audio loading
Diffstat (limited to 'rotord/src/libavwrapper.cpp')
-rw-r--r--rotord/src/libavwrapper.cpp66
1 files changed, 52 insertions, 14 deletions
diff --git a/rotord/src/libavwrapper.cpp b/rotord/src/libavwrapper.cpp
index 717667c..1fe0e5a 100644
--- a/rotord/src/libavwrapper.cpp
+++ b/rotord/src/libavwrapper.cpp
@@ -557,45 +557,45 @@ bool libav::decoder::avtry(int result, const std::string& msg) {
return true;
}
- void libav::ffms2_decoder::cleanup(){
+ void libav::video_decoder::cleanup(){
if (loaded) {
mutex.lock();
- FFMS_DestroyVideoSource(videosource);
+ FFMS_DestroyVideoSource(source);
mutex.unlock();
loaded=false;
}
}
-bool libav::ffms2_decoder::open(const std::string& filename){
+bool libav::video_decoder::open(const std::string& filename){
mutex.lock();
loaded=false;
- FFMS_Index *index = FFMS_MakeIndex(filename.c_str(), 0, 0, NULL, NULL, FFMS_IEH_IGNORE, NULL, NULL, &errinfo);
+ FFMS_Index *index = FFMS_MakeIndex(filename.c_str(), 0, 0, NULL, NULL, FFMS_IEH_IGNORE, NULL, NULL, &err);
if (index == NULL) {
- std::cerr<<"ffmpegsource: "<<errinfo.Buffer<<std::endl;
+ std::cerr<<"ffmpegsource: "<<err.Buffer<<std::endl;
mutex.unlock();
return false;
}
- int trackno = FFMS_GetFirstTrackOfType(index, FFMS_TYPE_VIDEO, &errinfo);
+ int trackno = FFMS_GetFirstTrackOfType(index, FFMS_TYPE_VIDEO, &err);
if (trackno < 0) {
- std::cerr<<"ffmpegsource: "<<errinfo.Buffer<<std::endl;
+ std::cerr<<"ffmpegsource: "<<err.Buffer<<std::endl;
mutex.unlock();
return false;
}
- videosource = FFMS_CreateVideoSource(filename.c_str(), trackno, index, 1, FFMS_SEEK_NORMAL, &errinfo);
- if (videosource == NULL) {
- std::cerr<<"ffmpegsource: "<<errinfo.Buffer<<std::endl;
+ source = FFMS_CreateVideoSource(filename.c_str(), trackno, index, 1, FFMS_SEEK_NORMAL, &err);
+ if (source == NULL) {
+ std::cerr<<"ffmpegsource: "<<err.Buffer<<std::endl;
mutex.unlock();
return false;
}
FFMS_DestroyIndex(index);
- videoprops = FFMS_GetVideoProperties(videosource);
- const FFMS_Frame *propframe = FFMS_GetFrame(videosource, 0, &errinfo);
+ props = FFMS_GetVideoProperties(source);
+ const FFMS_Frame *propframe = FFMS_GetFrame(source, 0, &err);
w=propframe->EncodedWidth;
h=propframe->EncodedHeight;
//propframe->EncodedPixelFormat;
- if (FFMS_SetOutputFormatV2(videosource, pixfmts, propframe->EncodedWidth, propframe->EncodedHeight, FFMS_RESIZER_BICUBIC, &errinfo)) {
- std::cerr<<"ffmpegsource: "<<errinfo.Buffer<<std::endl;
+ if (FFMS_SetOutputFormatV2(source, pixfmts, propframe->EncodedWidth, propframe->EncodedHeight, FFMS_RESIZER_BICUBIC, &err)) {
+ std::cerr<<"ffmpegsource: "<<err.Buffer<<std::endl;
mutex.unlock();
return false;
}
@@ -608,6 +608,44 @@ bool libav::ffms2_decoder::open(const std::string& filename){
return loaded;
}
+bool libav::audio_decoder::open(const std::string& filename){
+ mutex.lock();
+ loaded=false;
+ FFMS_Index *index = FFMS_MakeIndex(filename.c_str(),-1, 0, NULL, NULL, FFMS_IEH_IGNORE, NULL, NULL, &err);
+ if (index == NULL) {
+ std::cerr<<"ffmpegsource error making index for "<<filename<<":"<<err.Buffer<<std::endl;
+ mutex.unlock();
+ return false;
+ }
+ int trackno = FFMS_GetFirstTrackOfType(index, FFMS_TYPE_AUDIO, &err);
+ if (trackno < 0) {
+ std::cerr<<"ffmpegsource error finding audio track in "<<filename<<":"<<err.Buffer<<std::endl;
+ mutex.unlock();
+ return false;
+ }
+ std::cerr<<"ffmpegsource found audio track "<<trackno<<" in "<<filename<<":"<<err.Buffer<<std::endl;
+ source = FFMS_CreateAudioSource(filename.c_str(), trackno, index, FFMS_DELAY_TIME_ZERO, &err);
+ if (source == NULL) {
+ std::cerr<<"ffmpegsource error creating audio source from "<<filename<<":"<<err.Buffer<<std::endl;
+ mutex.unlock();
+ return false;
+ }
+ FFMS_DestroyIndex(index);
+ props = FFMS_GetAudioProperties(source);
+
+ std::cerr<<"ffmpegsource: successfully opened "<<filename<<std::endl;
+ loaded=true;
+ mutex.unlock();
+ return loaded;
+}
+ void libav::audio_decoder::cleanup(){
+ if (loaded) {
+ mutex.lock();
+ FFMS_DestroyAudioSource(source);
+ mutex.unlock();
+ loaded=false;
+ }
+}
///////////////////////////
// encoder methods //
///////////////////////////