~bwy/+junk/gnash-temp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// MediaHandler.h: Base class for media handlers
// 
//   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


#ifndef GNASH_MEDIAHANDLER_H
#define GNASH_MEDIAHANDLER_H

#include "MediaParser.h" // for videoCodecType and audioCodecType enums
#include "dsodefs.h" // DSOEXPORT
#include "VideoConverter.h"

#include <vector>
#include <memory>

// Forward declarations
namespace gnash {
    class IOChannel;
    namespace media {
        class VideoDecoder;
        class AudioDecoder;
        class AudioInfo;
        class VideoInfo;
        class VideoInput;
        class AudioInput;
    }
}

namespace gnash {

/// Gnash %media handling subsystem (libmedia)
//
/// The core Gnash lib will delegate any parsing decoding and encoding
/// of %media files to the %media subsystem.
///
/// The subsystem's entry point is a MediaHandler instance, which acts
/// as a factory for parsers, decoders and encoders.
///
/// Theoretically, it should be possible for actual MediaHandler
/// implementations to be loaded at runtime, altought this is not yet
/// implemented at time of writing (2008/10/27).
///
/// @todo fix http://wiki.gnashdev.org/wiki/index.php/Libmedia, is obsoleted
///
namespace media {

/// The MediaHandler class acts as a factory to provide parser and decoders
class DSOEXPORT MediaHandler
{
public:

    virtual ~MediaHandler() {}

    /// Return currently registered MediaHandler, possibly null.
    static MediaHandler* get()
    {
        return _handler.get();
    }

    /// Register a MediaHandler to use
    static void set(std::auto_ptr<MediaHandler> mh)
    {
        _handler = mh;
    }

    /// Return an appropriate MediaParser for given input
    //
    /// @param stream
    ///    Input stream, ownership transferred
    ///
    /// @return 0 if no parser could be created for the input
    ///
    /// NOTE: the default implementation returns an FLVParser for FLV input
    ///       or 0 for others.
    ///
    virtual std::auto_ptr<MediaParser>
        createMediaParser(std::auto_ptr<IOChannel> stream);

    /// Create a VideoDecoder for decoding what's specified in the VideoInfo
    //
    /// @param info VideoInfo class with all the info needed to decode
    ///             the sound correctly.
    /// @return     Will always return a valid VideoDecoder or throw a
    ///             gnash::MediaException if a fatal error occurs.
    virtual std::auto_ptr<VideoDecoder>
        createVideoDecoder(const VideoInfo& info)=0;

    /// Create an AudioDecoder for decoding what's specified in the AudioInfo
    //
    /// @param info AudioInfo class with all the info needed to decode
    ///             the sound correctly.
    /// @return     Will always return a valid AudioDecoder or throw a
    ///             gnash::MediaException if a fatal error occurs.
    virtual std::auto_ptr<AudioDecoder>
        createAudioDecoder(const AudioInfo& info)=0;

    /// Create an VideoConverter for converting between color spaces.
    //
    /// @param srcFormat The source image color space
    /// @param dstFormat The destination image color space
    ///
    /// @return A valid VideoConverter or a NULL auto_ptr if a fatal error
    ///         occurs.
    virtual std::auto_ptr<VideoConverter>
        createVideoConverter(ImgBuf::Type4CC srcFormat,
                ImgBuf::Type4CC dstFormat)=0;

    /// Return a VideoInput
    //
    /// This is always owned by the MediaHandler, but will remain alive
    /// as long as it is referenced by a Camera object.
    //
    /// @param index    The index of the VideoInput to return.
    /// @return         A Video Input corresponding to the specified index
    ///                 or null if it is not available. 
    virtual VideoInput* getVideoInput(size_t index) = 0;

    virtual AudioInput* getAudioInput(size_t index) = 0;

    /// Return a list of available cameras.
    //
    /// This is re-generated every time the function is called.
    virtual void cameraNames(std::vector<std::string>& names) const = 0;

    /// Return the number of bytes padding needed for input buffers
    //
    /// Bitstream readers are optimized to read several bytes at a time,
    /// and this should be used to allocate a large enough input buffer.
    virtual size_t getInputPaddingSize() const { return 0; }

protected:

    /// Create an AudioDecoder for FLASH codecs 
    //
    /// This method is attempted as a fallback in case
    /// a mediahandler-specific audio decoder couldn't be created
    /// for a FLASH codec.
    /// 
    /// @throws a MediaException if it can't create a decoder
    ///
    /// @param info
    ///     Informations about the audio. It is *required*
    ///     for info.type to be media::FLASH (caller should check
    ///     that before calling this).
    ///
    std::auto_ptr<AudioDecoder> createFlashAudioDecoder(const AudioInfo& info);

    /// Return true if input stream is an FLV
    //
    /// If this cannot read the necessary 3 bytes, it throws an IOException.
    bool isFLV(IOChannel& stream) throw (IOException);

    MediaHandler() {}

private:

    static std::auto_ptr<MediaHandler> _handler;
};


} // gnash.media namespace 
} // namespace gnash

#endif // __MEDIAHANDLER_H__