RDK Documentation (Open Sourced RDK Components)
audio_converter.h
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 #ifndef _AUDIO_CONVERTER_H_
20 #define _AUDIO_CONVERTER_H_
21 
22 #include <fstream>
23 #include <list>
24 #include "audio_capture_manager.h"
25 
27 {
28  public:
29  virtual int write_data(const char * ptr, unsigned int size) = 0;
30 };
31 
32 
34 {
35  public:
36  typedef enum
37  {
38  NO_CONVERSION = 0,
39  DOWNMIX,
40  DOWNSAMPLE,
41  DOWNMIX_AND_DOWNSAMPLE,
42  UNSUPPORTED_CONVERSION,
43  } conversion_ops_t;
44 
45  private:
46  const audiocapturemgr::audio_properties_t &m_in_props;
47  const audiocapturemgr::audio_properties_t &m_out_props;
48  bool m_downmix;
49  bool m_downsample;
50  audio_converter_sink &m_sink;
51 
52  //virtual int write_data(const char * ptr, unsigned int size){}
53  int process_conversion_params();
54  int downsample_and_downmix(const std::list<audio_buffer *> &queue, int size);
55  int passthrough(const std::list<audio_buffer *> &queue, int size);
56 
57  protected:
58  conversion_ops_t m_op;
59 
60  public:
62  virtual ~audio_converter() {}
63  virtual int convert(const std::list<audio_buffer *> &queue, unsigned int size);
64  void convert(const audio_buffer * buffer) {} //TODO
65  int downmix(const std::list<audio_buffer *> &queue, int size); //public because of the friend declaration
66 };
67 
69 {
70  private:
71  std::ofstream &m_file;
72  virtual int write_data(const char * ptr, unsigned int size) override;
73 
74  public:
75  audio_converter_file_sink(std::ofstream &file) : m_file(file) {}
76  virtual ~audio_converter_file_sink() {}
77 };
78 
79 
80 
82 {
83  private:
84  char * m_buffer;
85  unsigned int m_write_offset;
86 
87  public:
88  audio_converter_memory_sink(unsigned int max_size);
89  virtual ~audio_converter_memory_sink();
90  virtual int write_data(const char * ptr, unsigned int size) override;
91  inline char * get_buffer() { return m_buffer; }
92  inline unsigned int get_size() { return m_write_offset; }
93 
94  /* Direct access provided to downmix method in order to make optimizations
95  * that bypass the write method possible. */
96  friend int audio_converter::downmix(const std::list<audio_buffer *> &queue, int size);
97 };
98 
99 #endif //_AUDIO_CONVERTER_H_
audio_converter_sink
Definition: audio_converter.h:26
audio_converter_memory_sink
Definition: audio_converter.h:81
audio_buffer
Definition: audio_buffer.h:25
audiocapturemgr::audio_properties_t
Definition: audio_capture_manager.h:56
audio_converter
Definition: audio_converter.h:33
audio_converter_file_sink
Definition: audio_converter.h:68