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 https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
8 
9    class definition for the MP3 output module
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 #include "common/mp3.h"
20 #include "merge/generic_packetizer.h"
21 #include "merge/stream_property_preserver.h"
22 #include "merge/timestamp_calculator.h"
23 
24 class mp3_packetizer_c: public generic_packetizer_c {
25 private:
26   bool m_first_packet;
27   int64_t m_bytes_skipped;
28   int m_samples_per_sec, m_channels, m_samples_per_frame;
29   mtx::bytes::buffer_c m_byte_buffer;
30   bool m_codec_id_set, m_valid_headers_found;
31   timestamp_calculator_c m_timestamp_calculator;
32   stream_property_preserver_c<timestamp_c> m_discard_padding;
33   int64_t m_packet_duration;
34   std::vector<packet_extension_cptr> m_packet_extensions;
35 
36 public:
37   mp3_packetizer_c(generic_reader_c *p_reader, track_info_c &p_ti, int samples_per_sec, int channels, bool source_is_good);
38   virtual ~mp3_packetizer_c();
39 
40   virtual void set_headers();
41 
get_format_name()42   virtual translatable_string_c get_format_name() const {
43     return YT("MPEG-1/2 Audio Layer II/III");
44   }
45   virtual connection_result_e can_connect_to(generic_packetizer_c *src, std::string &error_message);
46 
47 protected:
48   virtual void process_impl(packet_cptr const &packet) override;
49   virtual memory_cptr get_mp3_packet(mp3_header_t *mp3header);
50 
51   virtual void handle_garbage(int64_t bytes);
52   virtual void flush_packets();
53 };
54