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    RealAudio output module
10 
11    Written by Moritz Bunkus <moritz@bunkus.org>.
12 */
13 
14 #include "common/common_pch.h"
15 
16 #include <matroska/KaxTracks.h>
17 
18 #include "common/codec.h"
19 #include "merge/connection_checks.h"
20 #include "output/p_realaudio.h"
21 
22 using namespace libmatroska;
23 
ra_packetizer_c(generic_reader_c * p_reader,track_info_c & p_ti,int samples_per_sec,int channels,int bits_per_sample,uint32_t fourcc)24 ra_packetizer_c::ra_packetizer_c(generic_reader_c *p_reader,
25                                  track_info_c &p_ti,
26                                  int samples_per_sec,
27                                  int channels,
28                                  int bits_per_sample,
29                                  uint32_t fourcc)
30   : generic_packetizer_c(p_reader, p_ti)
31   , m_samples_per_sec(samples_per_sec)
32   , m_channels(channels)
33   , m_bits_per_sample(bits_per_sample)
34   , m_fourcc(fourcc)
35 {
36   set_track_type(track_audio, TFA_SHORT_QUEUEING);
37 }
38 
~ra_packetizer_c()39 ra_packetizer_c::~ra_packetizer_c() {
40 }
41 
42 void
set_headers()43 ra_packetizer_c::set_headers() {
44   std::string codec_id = fmt::format("A_REAL/{0}{1}{2}{3}",
45                                       char(m_fourcc >> 24), char((m_fourcc >> 16) & 0xff), char((m_fourcc >> 8) & 0xff), char(m_fourcc & 0xff));
46   set_codec_id(balg::to_upper_copy(codec_id));
47   set_audio_sampling_freq(m_samples_per_sec);
48   set_audio_channels(m_channels);
49   set_audio_bit_depth(m_bits_per_sample);
50   set_codec_private(m_ti.m_private_data);
51 
52   generic_packetizer_c::set_headers();
53   m_track_entry->EnableLacing(false);
54 }
55 
56 void
process_impl(packet_cptr const & packet)57 ra_packetizer_c::process_impl(packet_cptr const &packet) {
58   add_packet(packet);
59 }
60 
61 connection_result_e
can_connect_to(generic_packetizer_c * src,std::string & error_message)62 ra_packetizer_c::can_connect_to(generic_packetizer_c *src,
63                                 std::string &error_message) {
64   ra_packetizer_c *psrc = dynamic_cast<ra_packetizer_c *>(src);
65   if (!psrc)
66     return CAN_CONNECT_NO_FORMAT;
67 
68   connect_check_a_samplerate(m_samples_per_sec, psrc->m_samples_per_sec);
69   connect_check_a_channels(m_channels,          psrc->m_channels);
70   connect_check_a_bitdepth(m_bits_per_sample,   psrc->m_bits_per_sample);
71 
72   return CAN_CONNECT_YES;
73 }
74