"Fossies" - the Fresh Open Source Software Archive

Member "mkvtoolnix-35.0.0/src/common/ac3.h" (22 Jun 2019, 3241 Bytes) of package /linux/misc/mkvtoolnix-35.0.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ac3.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2    mkvmerge -- utility for splicing together matroska files
    3    from component media subtypes
    4 
    5    Distributed under the GPL v2
    6    see the file COPYING for details
    7    or visit http://www.gnu.org/copyleft/gpl.html
    8 
    9    definitions and helper functions for AC-3 data
   10 
   11    Written by Moritz Bunkus <moritz@bunkus.org>.
   12 */
   13 
   14 #pragma once
   15 
   16 #include "common/common_pch.h"
   17 
   18 #include "common/byte_buffer.h"
   19 
   20 #define AC3_SYNC_WORD           0x0b77
   21 
   22 #define AC3_CHANNEL                  0
   23 #define AC3_MONO                     1
   24 #define AC3_STEREO                   2
   25 #define AC3_3F                       3
   26 #define AC3_2F1R                     4
   27 #define AC3_3F1R                     5
   28 #define AC3_2F2R                     6
   29 #define AC3_3F2R                     7
   30 #define AC3_CHANNEL1                 8
   31 #define AC3_CHANNEL2                 9
   32 #define AC3_DOLBY                   10
   33 #define AC3_CHANNEL_MASK            15
   34 
   35 #define AC3_LFE                     16
   36 
   37 #define EAC3_FRAME_TYPE_INDEPENDENT  0
   38 #define EAC3_FRAME_TYPE_DEPENDENT    1
   39 #define EAC3_FRAME_TYPE_AC3_CONVERT  2
   40 #define EAC3_FRAME_TYPE_RESERVED     3
   41 
   42 class codec_c;
   43 
   44 namespace mtx {
   45 
   46 namespace bits {
   47 class reader_c;
   48 }
   49 
   50 namespace ac3 {
   51 
   52 class frame_c {
   53 public:
   54   unsigned int m_sample_rate{}, m_bit_rate{}, m_channels{}, m_channel_layout{}, m_flags{}, m_bytes{}, m_bs_id{}, m_samples{}, m_frame_type{}, m_sub_stream_id{};
   55   unsigned int m_dialog_normalization_gain{}, m_dialog_normalization_gain_bit_position{};
   56   boost::optional<unsigned int> m_dialog_normalization_gain2, m_dialog_normalization_gain2_bit_position;
   57   uint64_t m_stream_position{}, m_garbage_size{};
   58   bool m_valid{}, m_lfeon{};
   59   memory_cptr m_data;
   60   std::vector<frame_c> m_dependent_frames;
   61 
   62 public:
   63   void init();
   64   bool is_eac3() const;
   65   codec_c get_codec() const;
   66   void add_dependent_frame(frame_c const &frame, unsigned char const *buffer, std::size_t buffer_size);
   67   bool decode_header(unsigned char const *buffer, std::size_t buffer_size);
   68   bool decode_header_type_eac3(mtx::bits::reader_c &bc);
   69   bool decode_header_type_ac3(mtx::bits::reader_c &bc);
   70 
   71   uint64_t get_effective_channel_layout() const;
   72   int get_effective_number_of_channels() const;
   73 
   74   std::string to_string(bool verbose) const;
   75 
   76   int find_in(memory_cptr const &buffer);
   77   int find_in(unsigned char const *buffer, std::size_t buffer_size);
   78 };
   79 
   80 class parser_c {
   81 protected:
   82   std::deque<frame_c> m_frames;
   83   mtx::bytes::buffer_c m_buffer;
   84   uint64_t m_parsed_stream_position, m_total_stream_position;
   85   frame_c m_current_frame;
   86   std::size_t m_garbage_size;
   87 
   88 public:
   89   parser_c();
   90   void add_bytes(memory_cptr const &mem);
   91   void add_bytes(unsigned char *const buffer, std::size_t size);
   92   void flush();
   93   std::size_t frame_available() const;
   94   frame_c get_frame();
   95   uint64_t get_parsed_stream_position() const;
   96   uint64_t get_total_stream_position() const;
   97 
   98   int find_consecutive_frames(unsigned char const *buffer, std::size_t buffer_size, std::size_t num_required_headers);
   99 
  100   void parse(bool end_of_stream);
  101 };
  102 
  103 bool verify_checksums(unsigned char const *buf, std::size_t size, bool full_buffer = false);
  104 void remove_dialog_normalization_gain(unsigned char *buf, std::size_t size);
  105 
  106 }}                              // namespace mtx::ac3