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 MPEG4 part 2 video 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 <deque>
19 
20 #include "common/mpeg4_p2.h"
21 #include "output/p_video_for_windows.h"
22 
23 class mpeg4_p2_video_packetizer_c: public video_for_windows_packetizer_c {
24 protected:
25   struct timestamp_duration_t {
26     int64_t m_timestamp, m_duration;
timestamp_duration_ttimestamp_duration_t27     timestamp_duration_t(int64_t timestamp, int64_t duration)
28       : m_timestamp(timestamp)
29       , m_duration(duration)
30     {
31     }
32   };
33 
34   struct statistics_t {
35     int m_num_dropped_timestamps, m_num_generated_timestamps;
36     int m_num_i_frames, m_num_p_frames, m_num_b_frames, m_num_n_vops;
37 
statistics_tstatistics_t38     statistics_t()
39       : m_num_dropped_timestamps(0)
40       , m_num_generated_timestamps(0)
41       , m_num_i_frames(0)
42       , m_num_p_frames(0)
43       , m_num_b_frames(0)
44       , m_num_n_vops(0)
45     {
46     }
47   };
48 
49   std::deque<mtx::mpeg4_p2::video_frame_t> m_ref_frames, m_b_frames;
50   std::deque<timestamp_duration_t> m_available_timestamps;
51   int64_t m_timestamps_generated, m_previous_timestamp;
52   bool m_aspect_ratio_extracted, m_input_is_native, m_output_is_native;
53   bool m_size_extracted;
54   mtx::mpeg4_p2::config_data_t m_config_data;
55   statistics_t m_statistics;
56 
57 public:
58   mpeg4_p2_video_packetizer_c(generic_reader_c *p_reader, track_info_c &p_ti, int64_t default_duration, int width, int height, bool input_is_native);
59   virtual ~mpeg4_p2_video_packetizer_c();
60 
get_format_name()61   virtual translatable_string_c get_format_name() const {
62     return YT("MPEG-4");
63   }
64 
65 protected:
66   virtual void process_impl(packet_cptr const &packet) override;
67   virtual void process_native(packet_cptr const &packet);
68   virtual void process_non_native(packet_cptr const &packet);
69   virtual void flush_impl();
70   virtual void flush_frames(bool end_of_file);
71   virtual void extract_aspect_ratio(const unsigned char *buffer, int size);
72   virtual void extract_size(const unsigned char *buffer, int size);
73   virtual void extract_config_data(packet_cptr const &packet);
74   virtual void fix_codec_string();
75   virtual void generate_timestamp_and_duration();
76   virtual void get_next_timestamp_and_duration(int64_t &timestamp, int64_t &duration);
77 };
78