| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | #include <osgDB/Registry> |
|---|
| 19 | #include <osgDB/FileNameUtils> |
|---|
| 20 | #include <osgDB/FileUtils> |
|---|
| 21 | |
|---|
| 22 | #include "DirectShowTexture" |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | class ReaderWriterDirectShow : public osgDB::ReaderWriter |
|---|
| 26 | { |
|---|
| 27 | public: |
|---|
| 28 | |
|---|
| 29 | ReaderWriterDirectShow() |
|---|
| 30 | { |
|---|
| 31 | supportsExtension("directshow", ""); |
|---|
| 32 | supportsExtension("avi", ""); |
|---|
| 33 | supportsExtension("wmv", "Windows Media Video format"); |
|---|
| 34 | supportsExtension("mpg", "Mpeg movie format"); |
|---|
| 35 | supportsExtension("mpeg", "Mpeg movie format"); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | virtual ~ReaderWriterDirectShow() |
|---|
| 39 | { |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | virtual const char * className() const |
|---|
| 43 | { |
|---|
| 44 | return "ReaderWriterDirectShow"; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | virtual ReadResult readImage(const std::string & filename, const osgDB::ReaderWriter::Options * options) const |
|---|
| 48 | { |
|---|
| 49 | const std::string ext = osgDB::getLowerCaseFileExtension(filename); |
|---|
| 50 | if (ext=="directshow") return readImageStream(osgDB::getNameLessExtension(filename),options); |
|---|
| 51 | if (! acceptsExtension(ext)) |
|---|
| 52 | return ReadResult::FILE_NOT_HANDLED; |
|---|
| 53 | return readImageStream(filename, options); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | ReadResult readImageStream(const std::string& filename, const osgDB::ReaderWriter::Options * options) const |
|---|
| 57 | { |
|---|
| 58 | osg::notify(osg::INFO) << "ReaderWriterDirectShow::readImage " << filename << std::endl; |
|---|
| 59 | const std::string path = osgDB::containsServerAddress(filename) ? |
|---|
| 60 | filename : |
|---|
| 61 | osgDB::findDataFile(filename, options); |
|---|
| 62 | |
|---|
| 63 | osg::ref_ptr<DirectShowImageStream> image_stream(new DirectShowImageStream); |
|---|
| 64 | |
|---|
| 65 | if (path.empty()) |
|---|
| 66 | { |
|---|
| 67 | std::map<std::string,std::string> map; |
|---|
| 68 | if (options) |
|---|
| 69 | { |
|---|
| 70 | map["captureWantedWidth"] = options->getPluginStringData("captureWantedWidth"); |
|---|
| 71 | map["captureWantedHeight"] = options->getPluginStringData("captureWantedHeight"); |
|---|
| 72 | map["captureWantedFps"] = options->getPluginStringData("captureWantedFps"); |
|---|
| 73 | map["captureVideoDevice"] = options->getPluginStringData("captureVideoDevice"); |
|---|
| 74 | map["captureSoundDevice"] = options->getPluginStringData("captureSoundDevice"); |
|---|
| 75 | map["captureSoundDeviceNbChannels"] = options->getPluginStringData("captureSoundDeviceNbChannels"); |
|---|
| 76 | } |
|---|
| 77 | if (filename != "capture") |
|---|
| 78 | { |
|---|
| 79 | if (!options || (options && options->getPluginStringData("captureVideoDevice").empty())) |
|---|
| 80 | map["captureVideoDevice"] = filename; |
|---|
| 81 | } |
|---|
| 82 | image_stream->setOptions(map); |
|---|
| 83 | |
|---|
| 84 | if (! image_stream->openCaptureDevices()) |
|---|
| 85 | return ReadResult::FILE_NOT_HANDLED; |
|---|
| 86 | return image_stream.release(); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | if (! image_stream->openFile(filename)) |
|---|
| 90 | return ReadResult::FILE_NOT_HANDLED; |
|---|
| 91 | |
|---|
| 92 | return image_stream.release(); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | private: |
|---|
| 96 | |
|---|
| 97 | }; |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | REGISTER_OSGPLUGIN(directshow, ReaderWriterDirectShow) |
|---|