mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2025-01-09 03:31:41 +00:00
Refactoring: use fourcc_c class in FLV reader
This commit is contained in:
parent
8c8c0ade0e
commit
95548b5f9a
@ -134,7 +134,6 @@ flv_tag_c::read(mm_io_cptr const &in) {
|
|||||||
|
|
||||||
flv_track_c::flv_track_c(char type)
|
flv_track_c::flv_track_c(char type)
|
||||||
: m_type{type}
|
: m_type{type}
|
||||||
, m_fourcc{}
|
|
||||||
, m_headers_read{}
|
, m_headers_read{}
|
||||||
, m_ptzr{-1}
|
, m_ptzr{-1}
|
||||||
, m_timecode{}
|
, m_timecode{}
|
||||||
@ -280,16 +279,16 @@ flv_reader_c::identify() {
|
|||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
for (auto track : m_tracks) {
|
for (auto track : m_tracks) {
|
||||||
std::vector<std::string> verbose_info;
|
std::vector<std::string> verbose_info;
|
||||||
if (track->m_fourcc == FOURCC('A', 'V', 'C', '1'))
|
if (track->m_fourcc.equiv("avc1"))
|
||||||
verbose_info.push_back("packetizer:mpeg4_p10_video");
|
verbose_info.push_back("packetizer:mpeg4_p10_video");
|
||||||
|
|
||||||
id_result_track(idx, track->is_audio() ? ID_RESULT_TRACK_AUDIO : ID_RESULT_TRACK_VIDEO,
|
id_result_track(idx, track->is_audio() ? ID_RESULT_TRACK_AUDIO : ID_RESULT_TRACK_VIDEO,
|
||||||
FOURCC('A', 'V', 'C', '1') == track->m_fourcc ? "AVC/h.264"
|
track->m_fourcc.equiv("AVC1") ? "AVC/h.264"
|
||||||
: FOURCC('F', 'L', 'V', '1') == track->m_fourcc ? "FLV1"
|
: track->m_fourcc.equiv("FLV1") ? "FLV1"
|
||||||
: FOURCC('F', 'L', 'V', '4') == track->m_fourcc ? "FLV4"
|
: track->m_fourcc.equiv("FLV4") ? "FLV4"
|
||||||
: FOURCC('A', 'A', 'C', ' ') == track->m_fourcc ? "AAC"
|
: track->m_fourcc.equiv("AAC ") ? "AAC"
|
||||||
: FOURCC('M', 'P', '3', ' ') == track->m_fourcc ? "MP3"
|
: track->m_fourcc.equiv("MP3 ") ? "MP3"
|
||||||
: "Unknown",
|
: "Unknown",
|
||||||
verbose_info);
|
verbose_info);
|
||||||
++idx;
|
++idx;
|
||||||
}
|
}
|
||||||
@ -312,17 +311,16 @@ flv_reader_c::create_packetizer(int64_t id) {
|
|||||||
|
|
||||||
m_ti.m_id = id;
|
m_ti.m_id = id;
|
||||||
|
|
||||||
if (track->m_fourcc == FOURCC('A', 'V', 'C', '1'))
|
if (track->m_fourcc.equiv("AVC1"))
|
||||||
create_v_avc_packetizer(track);
|
create_v_avc_packetizer(track);
|
||||||
|
|
||||||
else if ( (track->m_fourcc == FOURCC('F', 'L', 'V', '1'))
|
else if (track->m_fourcc.equiv("FLV1") || track->m_fourcc.equiv("FLV4"))
|
||||||
|| (track->m_fourcc == FOURCC('F', 'L', 'V', '4')))
|
|
||||||
create_v_generic_packetizer(track);
|
create_v_generic_packetizer(track);
|
||||||
|
|
||||||
else if (track->m_fourcc == FOURCC('A', 'A', 'C', ' '))
|
else if (track->m_fourcc.equiv("AAC "))
|
||||||
create_a_aac_packetizer(track);
|
create_a_aac_packetizer(track);
|
||||||
|
|
||||||
else if (track->m_fourcc == FOURCC('M', 'P', '3', ' '))
|
else if (track->m_fourcc.equiv("MP3 "))
|
||||||
create_a_mp3_packetizer(track);
|
create_a_mp3_packetizer(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,8 +347,8 @@ flv_reader_c::create_v_generic_packetizer(flv_track_cptr &track) {
|
|||||||
put_uint32_le(&bih.bi_height, track->m_v_height);
|
put_uint32_le(&bih.bi_height, track->m_v_height);
|
||||||
put_uint16_le(&bih.bi_planes, 1);
|
put_uint16_le(&bih.bi_planes, 1);
|
||||||
put_uint16_le(&bih.bi_bit_count, 24);
|
put_uint16_le(&bih.bi_bit_count, 24);
|
||||||
put_uint32_le(&bih.bi_compression, get_uint32_be(&track->m_fourcc));
|
|
||||||
put_uint32_le(&bih.bi_size_image, track->m_v_width * track->m_v_height * 3);
|
put_uint32_le(&bih.bi_size_image, track->m_v_width * track->m_v_height * 3);
|
||||||
|
track->m_fourcc.write(reinterpret_cast<unsigned char *>(&bih.bi_compression));
|
||||||
|
|
||||||
m_ti.m_private_data = reinterpret_cast<unsigned char *>(&bih);
|
m_ti.m_private_data = reinterpret_cast<unsigned char *>(&bih);
|
||||||
m_ti.m_private_size = sizeof(bih);
|
m_ti.m_private_size = sizeof(bih);
|
||||||
@ -438,7 +436,7 @@ flv_reader_c::process_audio_tag_sound_format(flv_track_cptr &track,
|
|||||||
if (!m_tag.m_data_size)
|
if (!m_tag.m_data_size)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
track->m_fourcc = FOURCC('A', 'A', 'C', ' ');
|
track->m_fourcc = "AAC ";
|
||||||
uint8_t aac_packet_type = m_in->read_uint8();
|
uint8_t aac_packet_type = m_in->read_uint8();
|
||||||
m_tag.m_data_size--;
|
m_tag.m_data_size--;
|
||||||
if (aac_packet_type != 0) {
|
if (aac_packet_type != 0) {
|
||||||
@ -474,8 +472,8 @@ flv_reader_c::process_audio_tag_sound_format(flv_track_cptr &track,
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (sound_format) {
|
switch (sound_format) {
|
||||||
case 2: track->m_fourcc = FOURCC('M', 'P', '3', ' '); break;
|
case 2: track->m_fourcc = "MP3 "; break;
|
||||||
case 14: track->m_fourcc = FOURCC('M', 'P', '3', ' '); break;
|
case 14: track->m_fourcc = "MP3 "; break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -521,7 +519,7 @@ flv_reader_c::process_video_tag_avc(flv_track_cptr &track) {
|
|||||||
if (4 > m_tag.m_data_size)
|
if (4 > m_tag.m_data_size)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
track->m_fourcc = FOURCC('A', 'V', 'C', '1');
|
track->m_fourcc = "AVC1";
|
||||||
uint8_t avc_packet_type = m_in->read_uint8();
|
uint8_t avc_packet_type = m_in->read_uint8();
|
||||||
track->m_v_cts_offset = static_cast<int64_t>(m_in->read_uint24_be());
|
track->m_v_cts_offset = static_cast<int64_t>(m_in->read_uint24_be());
|
||||||
m_tag.m_data_size -= 4;
|
m_tag.m_data_size -= 4;
|
||||||
@ -556,9 +554,9 @@ flv_reader_c::process_video_tag_avc(flv_track_cptr &track) {
|
|||||||
bool
|
bool
|
||||||
flv_reader_c::process_video_tag_generic(flv_track_cptr &track,
|
flv_reader_c::process_video_tag_generic(flv_track_cptr &track,
|
||||||
flv_tag_c::codec_type_e codec_id) {
|
flv_tag_c::codec_type_e codec_id) {
|
||||||
track->m_fourcc = flv_tag_c::CODEC_SORENSON_H263 == codec_id ? FOURCC('F', 'L', 'V', '1')
|
track->m_fourcc = flv_tag_c::CODEC_SORENSON_H263 == codec_id ? "FLV1"
|
||||||
: flv_tag_c::CODEC_VP6 == codec_id ? FOURCC('F', 'L', 'V', '4')
|
: flv_tag_c::CODEC_VP6 == codec_id ? "FLV4"
|
||||||
: FOURCC('B', 'U', 'G', '!');
|
: "BUG!";
|
||||||
track->m_headers_read = true;
|
track->m_headers_read = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -739,7 +737,7 @@ flv_reader_c::read(generic_packetizer_c *,
|
|||||||
mxdebug_if(m_debug, boost::format(" PTS in nanoseconds: %1%\n") % track->m_timecode);
|
mxdebug_if(m_debug, boost::format(" PTS in nanoseconds: %1%\n") % track->m_timecode);
|
||||||
|
|
||||||
int64_t duration = -1;
|
int64_t duration = -1;
|
||||||
if (track->m_v_frame_rate && (track->m_fourcc == FOURCC('A', 'V', 'C', '1')))
|
if (track->m_v_frame_rate && track->m_fourcc.equiv("AVC1"))
|
||||||
duration = 1000000000ll / track->m_v_frame_rate;
|
duration = 1000000000ll / track->m_v_frame_rate;
|
||||||
|
|
||||||
auto packet = new packet_t(track->m_payload, track->m_timecode, duration, 'I' == track->m_v_frame_type ? VFT_IFRAME : VFT_PFRAMEAUTOMATIC, VFT_NOBFRAME);
|
auto packet = new packet_t(track->m_payload, track->m_timecode, duration, 'I' == track->m_v_frame_type ? VFT_IFRAME : VFT_PFRAMEAUTOMATIC, VFT_NOBFRAME);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
#include "common/byte_buffer.h"
|
#include "common/byte_buffer.h"
|
||||||
|
#include "common/fourcc.h"
|
||||||
#include "common/mm_io.h"
|
#include "common/mm_io.h"
|
||||||
#include "merge/pr_generic.h"
|
#include "merge/pr_generic.h"
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ operator <<(std::ostream &out,
|
|||||||
class flv_track_c {
|
class flv_track_c {
|
||||||
public:
|
public:
|
||||||
char m_type; // 'v' for video, 'a' for audio
|
char m_type; // 'v' for video, 'a' for audio
|
||||||
uint32_t m_fourcc;
|
fourcc_c m_fourcc;
|
||||||
bool m_headers_read;
|
bool m_headers_read;
|
||||||
|
|
||||||
memory_cptr m_payload, m_private_data, m_extra_data;
|
memory_cptr m_payload, m_private_data, m_extra_data;
|
||||||
|
@ -164,6 +164,8 @@ TEST(FourCC, WritingToMemory) {
|
|||||||
|
|
||||||
fourcc_c big_f{big}, little_f{little, fourcc_c::little_endian};
|
fourcc_c big_f{big}, little_f{little, fourcc_c::little_endian};
|
||||||
|
|
||||||
|
ASSERT_EQ(big_f, little_f);
|
||||||
|
|
||||||
memset(mem->get_buffer(), 0, 4);
|
memset(mem->get_buffer(), 0, 4);
|
||||||
EXPECT_EQ(4u, big_f.write(mem));
|
EXPECT_EQ(4u, big_f.write(mem));
|
||||||
EXPECT_EQ(big, get_uint32_be(mem->get_buffer()));
|
EXPECT_EQ(big, get_uint32_be(mem->get_buffer()));
|
||||||
|
Loading…
Reference in New Issue
Block a user