From fa14e7d5f29c6850234f18d8f631d8e712658535 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 5 Mar 2009 10:57:54 +0000 Subject: [PATCH] Added quick proof of concept for live video streaming under linux --- src/osgPlugins/ffmpeg/FFmpegDecoder.cpp | 39 ++++++++++++++++++-- src/osgPlugins/ffmpeg/FFmpegHeaders.hpp | 1 + src/osgPlugins/ffmpeg/ReaderWriterFFmpeg.cpp | 15 ++++++-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp b/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp index 6c74fe443..ea8bd049f 100644 --- a/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp +++ b/src/osgPlugins/ffmpeg/FFmpegDecoder.cpp @@ -35,7 +35,6 @@ FFmpegDecoder::~FFmpegDecoder() } - bool FFmpegDecoder::open(const std::string & filename) { try @@ -43,9 +42,43 @@ bool FFmpegDecoder::open(const std::string & filename) // Open video file AVFormatContext * p_format_context = 0; - if (av_open_input_file(&p_format_context, filename.c_str(), 0, 0, 0) != 0) - throw std::runtime_error("av_open_input_file() failed"); + if (filename.compare(0, 5, "/dev/")==0) + { + avdevice_register_all(); + + osg::notify(osg::NOTICE)<<"Attempting to stream "< #include #include +#include #ifdef USE_SWSCALE #include diff --git a/src/osgPlugins/ffmpeg/ReaderWriterFFmpeg.cpp b/src/osgPlugins/ffmpeg/ReaderWriterFFmpeg.cpp index 794cb16d2..fd3ac2ba6 100644 --- a/src/osgPlugins/ffmpeg/ReaderWriterFFmpeg.cpp +++ b/src/osgPlugins/ffmpeg/ReaderWriterFFmpeg.cpp @@ -40,8 +40,12 @@ public: virtual ReadResult readImage(const std::string & filename, const osgDB::ReaderWriter::Options * options) const { + if (filename.compare(0, 5, "/dev/")==0) + { + return readImageStream(filename, options); + } + const std::string ext = osgDB::getLowerCaseFileExtension(filename); - if (! acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; @@ -52,11 +56,16 @@ public: if (path.empty()) return ReadResult::FILE_NOT_FOUND; - osg::notify(osg::INFO) << "ReaderWriterFFmpeg::readImage " << path << std::endl; + return readImageStream(filename, options); + } + + ReadResult readImageStream(const std::string& filename, const osgDB::ReaderWriter::Options * options) const + { + osg::notify(osg::INFO) << "ReaderWriterFFmpeg::readImage " << filename << std::endl; osg::ref_ptr image_stream(new osgFFmpeg::FFmpegImageStream); - if (! image_stream->open(path)) + if (! image_stream->open(filename)) return ReadResult::FILE_NOT_HANDLED; return image_stream.release();