root/OpenSceneGraph/trunk/src/osgPlugins/directshow/ReaderWriterDirectShow.cpp @ 10922

Revision 10922, 3.6 kB (checked in by robert, 4 years ago)

From Serge Lages, "Here is a modified fix. It doesn't break the other patch for this plugin as they are for different files. I've only added the file formats handled by default with DirectShow? (based on its Wikipedia page)."

Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 2009 Tharsis Software
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12 *
13 * Authors:
14 *         Cedric Pinson <cedric.pinson@plopbyte.net>
15*/
16
17
18#include <osgDB/Registry>
19#include <osgDB/FileNameUtils>
20#include <osgDB/FileUtils>
21
22#include "DirectShowTexture"
23
24
25class ReaderWriterDirectShow : public osgDB::ReaderWriter
26{
27public:
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()) // try with capture
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
95private:
96
97};
98
99
100
101REGISTER_OSGPLUGIN(directshow, ReaderWriterDirectShow)
Note: See TracBrowser for help on using the browser.