ReadFileIntoString() modified to return OK when the file is empty
[asdcplib.git] / src / PCMDataProviders.h
1 /*
2 Copyright (c) 2013-2013, John Hurst
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9    notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11    notice, this list of conditions and the following disclaimer in the
12    documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14    derived from this software without specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 /*! \file    PCMDataProviders.h
28     \version $Id$
29     \brief   PCM sample data providers for WAV, AtmosSync and Silence.
30 */
31
32 #ifndef _PCMDATAPROVIDERS_H_
33 #define _PCMDATAPROVIDERS_H_
34
35 #include <AS_DCP.h>
36 #include <AtmosSyncChannel_Generator.h>
37
38 namespace ASDCP
39 {
40
41   // PCM Data Provider Interface
42   class PCMDataProviderInterface
43   {
44       ASDCP_NO_COPY_CONSTRUCT(PCMDataProviderInterface);
45
46   public:
47       PCMDataProviderInterface() {};
48       virtual ~PCMDataProviderInterface() = 0;
49       virtual Result_t PutSample(const ui32_t numChannels, byte_t* buf, ui32_t* bytesWritten) = 0;
50       virtual Result_t ReadFrame() = 0;
51       virtual Result_t FillAudioDescriptor(PCM::AudioDescriptor& ADesc) const = 0;
52       virtual Result_t Reset() = 0;
53   };
54
55   // WAV file implementation of the PCM Data Provider Interface
56   class WAVDataProvider : public PCMDataProviderInterface
57   {
58       ASDCP_NO_COPY_CONSTRUCT(WAVDataProvider);
59       PCM::WAVParser       m_Parser;
60       PCM::FrameBuffer     m_FB;
61       PCM::AudioDescriptor m_ADesc;
62       const byte_t*        m_ptr;
63       ui32_t               m_SampleSize;
64
65   public:
66       WAVDataProvider();
67       virtual ~WAVDataProvider();
68       virtual Result_t PutSample(const ui32_t numChannels, byte_t* buf, ui32_t* bytesWritten);
69       virtual Result_t ReadFrame();
70       virtual Result_t FillAudioDescriptor(PCM::AudioDescriptor& ADesc) const;
71       virtual Result_t Reset();
72       Result_t OpenRead(const char* filename, const Rational& PictureRate);
73
74   };
75
76   // Atmos Sync Channel implementation of the PCM Data Provider Interface
77   class AtmosSyncDataProvider : public PCMDataProviderInterface
78   {
79       ASDCP_NO_COPY_CONSTRUCT(AtmosSyncDataProvider);
80       PCM::AtmosSyncChannelGenerator m_Generator;
81       PCM::FrameBuffer                m_FB;
82       PCM::AudioDescriptor            m_ADesc;
83       const byte_t*                   m_ptr;
84       ui32_t                          m_SampleSize;
85
86   public:
87       AtmosSyncDataProvider(const ui16_t bitsPerSample, const ui32_t sampleRate,
88                             const ASDCP::Rational& PictureRate, const byte_t* uuid);
89       virtual ~AtmosSyncDataProvider();
90       virtual Result_t PutSample(const ui32_t numChannels, byte_t* buf, ui32_t* bytesWritten);
91       virtual Result_t ReadFrame();
92       virtual Result_t FillAudioDescriptor(PCM::AudioDescriptor& ADesc) const;
93       virtual Result_t Reset();
94   };
95
96   // Silence Channel(s) implementation of the PCM Data Provider Interface
97   class SilenceDataProvider : public PCMDataProviderInterface
98   {
99       ASDCP_NO_COPY_CONSTRUCT(SilenceDataProvider);
100       PCM::AudioDescriptor  m_ADesc;
101       ui32_t                m_SampleSize;
102
103   public:
104       SilenceDataProvider(const ui16_t numChannels, const ui16_t bitsPerSample,
105                           const ui32_t sampleRate, const ASDCP::Rational& editRate);
106       virtual ~SilenceDataProvider();
107       virtual Result_t PutSample(const ui32_t numChannels, byte_t* buf, ui32_t* bytesWritten);
108       virtual Result_t ReadFrame();
109       virtual Result_t FillAudioDescriptor(PCM::AudioDescriptor& ADesc) const;
110       virtual Result_t Reset();
111   };
112
113 } // namespace ASDCP
114
115 #endif // _PCMDATAPROVIDERS_H_
116
117 //
118 // end PCMDataProviders.h
119 //