diff --git a/src/input/r_aac.cpp b/src/input/r_aac.cpp index 40a0fb5ca..665a9cb2b 100644 --- a/src/input/r_aac.cpp +++ b/src/input/r_aac.cpp @@ -73,6 +73,7 @@ aac_reader_c::aac_reader_c(track_info_c &_ti) throw (error_c): generic_reader_c(_ti), sbr_status_set(false) { + int adif, detected_profile; try { diff --git a/src/input/r_avi.cpp b/src/input/r_avi.cpp index 3d70f6ca6..f1b8353c0 100644 --- a/src/input/r_avi.cpp +++ b/src/input/r_avi.cpp @@ -80,10 +80,16 @@ avi_reader_c::avi_reader_c(track_info_c &_ti) throw (error_c): generic_reader_c(_ti), divx_type(DIVX_TYPE_NONE), - avi(NULL), vptzr(-1), - fps(1.0), video_frames_read(0), max_video_frames(0), dropped_video_frames(0), - act_wchar(0), rederive_keyframes(false), - bytes_to_process(0), bytes_processed(0) { + avi(NULL), + vptzr(-1), + fps(1.0), + video_frames_read(0), + max_video_frames(0), + dropped_video_frames(0), + act_wchar(0), + rederive_keyframes(false), + bytes_to_process(0), + bytes_processed(0) { int64_t size; diff --git a/src/input/r_corepicture.cpp b/src/input/r_corepicture.cpp index 0380ad356..f83a2cf04 100644 --- a/src/input/r_corepicture.cpp +++ b/src/input/r_corepicture.cpp @@ -49,7 +49,7 @@ public: int corepicture_reader_c::probe_file(mm_text_io_c *io, - int64_t) { + int64_t) { try { corepicture_xml_find_root_c root_finder(io); @@ -68,7 +68,8 @@ corepicture_reader_c::probe_file(mm_text_io_c *io, corepicture_reader_c::corepicture_reader_c(track_info_c &_ti) throw (error_c): generic_reader_c(_ti), - m_width(-1), m_height(-1) { + m_width(-1), + m_height(-1) { try { m_xml_source = new mm_text_io_c(new mm_file_io_c(ti.fname)); diff --git a/src/input/r_corepicture.h b/src/input/r_corepicture.h index ea5a7a830..19a7160e0 100644 --- a/src/input/r_corepicture.h +++ b/src/input/r_corepicture.h @@ -52,9 +52,11 @@ struct corepicture_pic_t { corepicture_panorama_type m_pan_type; corepicture_pic_t(): - m_time(-1), m_end_time(-1), m_pic_type(COREPICTURE_TYPE_UNKNOWN), - m_pan_type(COREPICTURE_PAN_UNKNOWN) - {} + m_time(-1), + m_end_time(-1), + m_pic_type(COREPICTURE_TYPE_UNKNOWN), + m_pan_type(COREPICTURE_PAN_UNKNOWN) { + } bool is_valid() const { return (COREPICTURE_TYPE_UNKNOWN != m_pic_type) && (COREPICTURE_PAN_UNKNOWN != m_pan_type) && (m_url != "") && (0 <= m_time); diff --git a/src/input/r_dts.cpp b/src/input/r_dts.cpp index b2db05057..668412710 100644 --- a/src/input/r_dts.cpp +++ b/src/input/r_dts.cpp @@ -55,8 +55,8 @@ dts_reader_c::dts_reader_c(track_info_c &_ti) throw (error_c): generic_reader_c(_ti), cur_buf(0), - dts14_to_16(false), swap_bytes(false) { - int pos; + dts14_to_16(false), + swap_bytes(false) { try { io = new mm_file_io_c(ti.fname); @@ -77,9 +77,9 @@ dts_reader_c::dts_reader_c(track_info_c &_ti) mxverb(3, "DTS: 14->16 %d swap %d\n", dts14_to_16, swap_bytes); decode_buffer(READ_SIZE); - pos = find_dts_header((const unsigned char *)buf[cur_buf], READ_SIZE, &dtsheader); + int pos = find_dts_header((const unsigned char *)buf[cur_buf], READ_SIZE, &dtsheader); - if (pos < 0) + if (0 > pos) throw error_c("dts_reader: No valid DTS packet found in the first READ_SIZE bytes.\n"); bytes_processed = 0; @@ -98,12 +98,12 @@ dts_reader_c::~dts_reader_c() { int dts_reader_c::decode_buffer(int len) { if (swap_bytes) { - swab((char *)buf[cur_buf], (char *)buf[cur_buf^1], len); + swab((char *)buf[cur_buf], (char *)buf[cur_buf ^ 1], len); cur_buf ^= 1; } if (dts14_to_16) { - dts_14_to_dts_16(buf[cur_buf], len / 2, buf[cur_buf^1]); + dts_14_to_dts_16(buf[cur_buf], len / 2, buf[cur_buf ^ 1]); cur_buf ^= 1; len = len * 7 / 8; } diff --git a/src/input/r_matroska.h b/src/input/r_matroska.h index b45103941..6b3fb6ca5 100644 --- a/src/input/r_matroska.h +++ b/src/input/r_matroska.h @@ -94,34 +94,50 @@ struct kax_track_t { memory_cptr first_frame_data; - kax_track_t(): tnum(0), tuid(0), - ms_compat(false), - type(' '), sub_type(' '), - passthrough(false), - min_cache(0), max_cache(0), - lacing_flag(false), - default_duration(0), - v_width(0), v_height(0), v_dwidth(0), v_dheight(0), - v_pcleft(0), v_pctop(0), v_pcright(0), v_pcbottom(0), - v_stereo_mode(STEREO_MODE_UNSPECIFIED), - v_frate(0.0), - v_bframes(false), - a_channels(0), a_bps(0), a_formattag(0), - a_sfreq(0.0), a_osfreq(0.0), - private_data(NULL), private_size(0), - default_track(false), - language("eng"), - units_processed(0), - ok(false), - previous_timecode(0), - tags(NULL), - ptzr(0), - headers_set(false), - ignore_duration_hack(false) { + kax_track_t(): + tnum(0), + tuid(0), + ms_compat(false), + type(' '), + sub_type(' '), + passthrough(false), + min_cache(0), + max_cache(0), + lacing_flag(false), + default_duration(0), + v_width(0), + v_height(0), + v_dwidth(0), + v_dheight(0), + v_pcleft(0), + v_pctop(0), + v_pcright(0), + v_pcbottom(0), + v_stereo_mode(STEREO_MODE_UNSPECIFIED), + v_frate(0.0), + v_bframes(false), + a_channels(0), + a_bps(0), + a_formattag(0), + a_sfreq(0.0), + a_osfreq(0.0), + private_data(NULL), + private_size(0), + default_track(false), + language("eng"), + units_processed(0), + ok(false), + previous_timecode(0), + tags(NULL), + ptzr(0), + headers_set(false), + ignore_duration_hack(false) { + memset(v_fourcc, 0, 5); memset(headers, 0, 3 * sizeof(unsigned char *)); memset(header_sizes, 0, 3 * sizeof(uint32_t)); } + ~kax_track_t() { safefree(private_data); if (NULL != tags) diff --git a/src/input/r_mpeg.h b/src/input/r_mpeg.h index bbadc6157..3203cbbb3 100644 --- a/src/input/r_mpeg.h +++ b/src/input/r_mpeg.h @@ -73,12 +73,28 @@ struct mpeg_ps_track_t { int buffer_usage, buffer_size; mpeg_ps_track_t(): - ptzr(-1), type(0), id(0), sort_key(0), fourcc(0), timecode_offset(-1), - v_version(0), v_width(0), v_height(0), v_dwidth(0), v_dheight(0), - v_frame_rate(0), v_aspect_ratio(0), - raw_seq_hdr(NULL), raw_seq_hdr_size(0), - a_channels(0), a_sample_rate(0), a_bits_per_sample(0), a_bsid(0), - buffer(NULL), buffer_usage(0), buffer_size(0) { + ptzr(-1), + type(0), + id(0), + sort_key(0), + fourcc(0), + timecode_offset(-1), + v_version(0), + v_width(0), + v_height(0), + v_dwidth(0), + v_dheight(0), + v_frame_rate(0), + v_aspect_ratio(0), + raw_seq_hdr(NULL), + raw_seq_hdr_size(0), + a_channels(0), + a_sample_rate(0), + a_bits_per_sample(0), + a_bsid(0), + buffer(NULL), + buffer_usage(0), + buffer_size(0) { }; void use_buffer(int size) { diff --git a/src/input/r_ogm.cpp b/src/input/r_ogm.cpp index 40933790a..5b42ef35d 100644 --- a/src/input/r_ogm.cpp +++ b/src/input/r_ogm.cpp @@ -281,7 +281,7 @@ ogm_reader_c::probe_file(mm_io_c *io, int64_t size) { unsigned char data[4]; - if (size < 4) + if (4 > size) return 0; try { io->setFilePointer(0, seek_beginning); @@ -305,10 +305,8 @@ ogm_reader_c::ogm_reader_c(track_info_c &_ti) generic_reader_c(_ti) { try { - io = new mm_file_io_c(ti.fname); - io->setFilePointer(0, seek_end); - file_size = io->getFilePointer(); - io->setFilePointer(0, seek_beginning); + io = new mm_file_io_c(ti.fname); + file_size = io->get_size(); } catch (...) { throw error_c("ogm_reader: Could not open the source file."); } @@ -358,18 +356,16 @@ ogm_reader_c::read_page(ogg_page *og) { np = ogg_sync_pageseek(&oy, og); // np == 0 means that there is not enough data for a complete page. - if (np <= 0) { + if (0 >= np) { // np < 0 is the error case. Should not happen with local OGG files. - if (np < 0) - mxwarn("ogm_reader: Could not find the next Ogg " - "page. This indicates a damaged Ogg/Ogm file. Will try to " - "continue.\n"); + if (0 > np) + mxwarn("ogm_reader: Could not find the next Ogg page. This indicates a damaged Ogg/Ogm file. Will try to continue.\n"); buf = (unsigned char *)ogg_sync_buffer(&oy, BUFFER_SIZE); if (!buf) mxerror("ogm_reader: ogg_sync_buffer failed\n"); - if ((nread = io->read(buf, BUFFER_SIZE)) <= 0) + if (0 >= (nread = io->read(buf, BUFFER_SIZE))) return 0; ogg_sync_wrote(&oy, nread); @@ -387,7 +383,7 @@ ogm_reader_c::create_packetizer(int64_t tid) { ogm_demuxer_cptr dmx; generic_packetizer_c *ptzr; - if ((tid < 0) || (tid >= sdemuxers.size())) + if ((0 > tid) || (sdemuxers.size() <= tid)) return; dmx = sdemuxers[tid]; @@ -402,8 +398,8 @@ ogm_reader_c::create_packetizer(int64_t tid) { ptzr = dmx->create_packetizer(ti); - if (ptzr != NULL) - dmx->ptzr = add_packetizer(ptzr); + if (NULL != ptzr) + dmx->ptzr = add_packetizer(ptzr); ti.language.clear(); ti.track_name.clear(); @@ -428,8 +424,7 @@ ogm_reader_c::packet_available() { return 0; for (i = 0; i < sdemuxers.size(); i++) - if ((-1 != sdemuxers[i]->ptzr) && - !PTZR(sdemuxers[i]->ptzr)->packet_available()) + if ((-1 != sdemuxers[i]->ptzr) && !PTZR(sdemuxers[i]->ptzr)->packet_available()) return 0; return 1; @@ -455,7 +450,6 @@ void ogm_reader_c::handle_new_stream(ogg_page *og) { ogg_stream_state os; ogg_packet op; - ogm_demuxer_c *dmx = NULL; if (ogg_stream_init(&os, ogg_page_serialno(og))) { mxwarn("ogm_reader: ogg_stream_init for stream number %u failed. Will try to continue and ignore this stream.", (unsigned int)sdemuxers.size()); @@ -466,28 +460,30 @@ ogm_reader_c::handle_new_stream(ogg_page *og) { ogg_stream_pagein(&os, og); ogg_stream_packetout(&os, &op); + ogm_demuxer_c *dmx = NULL; + /* * Check the contents for known stream headers. This one is the * standard Vorbis header. */ - if ((op.bytes >= 7) && !strncmp((char *)&op.packet[1], "vorbis", 6)) + if ((7 <= op.bytes) && !strncmp((char *)&op.packet[1], "vorbis", 6)) dmx = new ogm_a_vorbis_demuxer_c(this); - else if ((op.bytes >= 7) && !strncmp((char *)&op.packet[1], "theora", 6)) + else if ((7 <= op.bytes) && !strncmp((char *)&op.packet[1], "theora", 6)) dmx = new ogm_v_theora_demuxer_c(this); - else if ((op.bytes >= 8) && !memcmp(&op.packet[1], "kate\0\0\0", 7)) + else if ((8 <= op.bytes) && !memcmp(&op.packet[1], "kate\0\0\0", 7)) dmx = new ogm_s_kate_demuxer_c(this); // FLAC - else if ((op.bytes >= 4) && !strncmp((char *)op.packet, "fLaC", 4)) { + else if ((4 <= op.bytes) && !strncmp((char *)op.packet, "fLaC", 4)) { #if !defined(HAVE_FLAC_FORMAT_H) if (demuxing_requested('a', sdemuxers.size())) mxerror("mkvmerge has not been compiled with FLAC support but handling of this stream has been requested.\n"); else { - dmx = new ogm_demuxer_c(this); - dmx->stype = OGM_STREAM_TYPE_A_FLAC; + dmx = new ogm_demuxer_c(this); + dmx->stype = OGM_STREAM_TYPE_A_FLAC; dmx->in_use = true; } @@ -618,12 +614,9 @@ ogm_reader_c::process_header_packets(ogm_demuxer_cptr dmx) { */ int ogm_reader_c::read_headers() { - int i; - bool done; - ogm_demuxer_cptr dmx; ogg_page og; - done = false; + bool done = false; while (!done) { // Make sure we have a page that we can work with. if (read_page(&og) == FILE_STATUS_DONE) @@ -638,8 +631,9 @@ ogm_reader_c::read_headers() { done = true; + int i; for (i = 0; i < sdemuxers.size(); i++) { - dmx = sdemuxers[i]; + ogm_demuxer_cptr &dmx = sdemuxers[i]; if (!dmx->headers_read && dmx->in_use) { done = false; break; @@ -661,14 +655,13 @@ ogm_reader_c::read_headers() { file_status_e ogm_reader_c::read(generic_packetizer_c *, bool) { - int i; - ogg_page og; - // Some tracks may contain huge gaps. We don't want to suck in the complete // file. if (get_queued_bytes() > 20 * 1024 * 1024) return FILE_STATUS_HOLDING; + ogg_page og; + do { // Make sure we have a page that we can work with. if (read_page(&og) == FILE_STATUS_DONE) { @@ -681,6 +674,7 @@ ogm_reader_c::read(generic_packetizer_c *, process_page(&og); } while (ogg_page_bos(&og)); + int i; // Are there streams that have not finished yet? for (i = 0; i < sdemuxers.size(); i++) if (!sdemuxers[i]->eos && sdemuxers[i]->in_use) @@ -698,7 +692,6 @@ ogm_reader_c::get_progress() { void ogm_reader_c::identify() { - string codec; vector verbose_info; int i; @@ -727,30 +720,28 @@ ogm_reader_c::identify() { void ogm_reader_c::handle_stream_comments() { - int i, j, cch; - ogm_demuxer_cptr dmx; counted_ptr > comments; - vector comment, chapter_strings; string title; - bool charset_warning_printed; - charset_warning_printed = false; - cch = utf8_init(ti.chapter_charset); + bool charset_warning_printed = false; + int cch = utf8_init(ti.chapter_charset); + int i; for (i = 0; i < sdemuxers.size(); i++) { - dmx = sdemuxers[i]; - if ((dmx->stype == OGM_STREAM_TYPE_A_FLAC) || - (dmx->packet_data.size() < 2)) + ogm_demuxer_cptr &dmx = sdemuxers[i]; + if ((OGM_STREAM_TYPE_A_FLAC == dmx->stype) || (2 > dmx->packet_data.size())) continue; + comments = extract_vorbis_comments(dmx->packet_data[1]); if (comments->empty()) continue; - chapter_strings.clear(); + vector chapter_strings; + int j; for (j = 0; comments->size() > j; j++) { mxverb(2, "ogm_reader: commment for #%d for %d: %s\n", j, i, (*comments)[j].c_str()); - comment = split((*comments)[j], "=", 2); + vector comment = split((*comments)[j], "=", 2); if (comment.size() != 2) continue; @@ -761,26 +752,26 @@ ogm_reader_c::handle_stream_comments() { if (-1 != index) dmx->language = iso639_languages[index].iso639_2_code; else { - string lang; - int pos1, pos2; - lang = comment[1]; - pos1 = lang.find("["); - while (pos1 >= 0) { - pos2 = lang.find("]", pos1); - if (pos2 == -1) + string lang = comment[1]; + int pos1 = lang.find("["); + while (0 <= pos1) { + int pos2 = lang.find("]", pos1); + if (-1 == pos2) pos2 = lang.length() - 1; lang.erase(pos1, pos2 - pos1 + 1); pos1 = lang.find("["); } + pos1 = lang.find("("); - while (pos1 >= 0) { - pos2 = lang.find(")", pos1); - if (pos2 == -1) + while (0 <= pos1) { + int pos2 = lang.find(")", pos1); + if (-1 == pos2) pos2 = lang.length() - 1; lang.erase(pos1, pos2 - pos1 + 1); pos1 = lang.find("("); } + index = map_to_iso639_2_code(lang.c_str()); if (-1 != index) dmx->language = iso639_languages[index].iso639_2_code; @@ -793,29 +784,24 @@ ogm_reader_c::handle_stream_comments() { chapter_strings.push_back((*comments)[j]); } - if (((title != "") || (chapter_strings.size() > 0)) && - !charset_warning_printed && (ti.chapter_charset == "")) { - mxwarn("The Ogg/OGM file '%s' contains chapter or title information. " - "Unfortunately the charset used to store this information in " - "the file cannot be identified unambiguously. mkvmerge assumes " - "that your system's current charset is appropriate. This can " - "be overridden with the '--chapter-charset ' " - "switch.\n", ti.fname.c_str()); + if (((title != "") || (chapter_strings.size() > 0)) && !charset_warning_printed && (ti.chapter_charset == "")) { + mxwarn("The Ogg/OGM file '%s' contains chapter or title information. Unfortunately the charset used to store this information in " + "the file cannot be identified unambiguously. mkvmerge assumes that your system's current charset is appropriate. This can " + "be overridden with the '--chapter-charset ' switch.\n", ti.fname.c_str()); charset_warning_printed = true; } if (title != "") { title = to_utf8(cch, title); - if (!segment_title_set && (segment_title.length() == 0) && - (dmx->stype == OGM_STREAM_TYPE_V_MSCOMP)) { - segment_title = title; + if (!segment_title_set && segment_title.empty() && (OGM_STREAM_TYPE_V_MSCOMP == dmx->stype)) { + segment_title = title; segment_title_set = true; } dmx->title = title.c_str(); - title = ""; + title = ""; } - if (!chapter_strings.empty() && !ti.no_chapters && (kax_chapters == NULL)) { + if (!chapter_strings.empty() && !ti.no_chapters && (NULL == kax_chapters)) { try { auto_ptr out(new mm_mem_io_c(NULL, 0, 1000)); @@ -845,10 +831,20 @@ ogm_reader_c::add_available_track_ids() { ogm_demuxer_c::ogm_demuxer_c(ogm_reader_c *p_reader): reader(p_reader), - ptzr(-1), stype(OGM_STREAM_TYPE_UNKNOWN), serialno(0), eos(0), units_processed(0), - num_header_packets(2), num_non_header_packets(0), headers_read(false), - first_granulepos(0), last_granulepos(0), last_keyframe_number(-1), default_duration(0), + ptzr(-1), + stype(OGM_STREAM_TYPE_UNKNOWN), + serialno(0), + eos(0), + units_processed(0), + num_header_packets(2), + num_non_header_packets(0), + headers_read(false), + first_granulepos(0), + last_granulepos(0), + last_keyframe_number(-1), + default_duration(0), in_use(false) { + memset(&os, 0, sizeof(ogg_stream_state)); } @@ -876,8 +872,6 @@ ogm_demuxer_c::get_duration_and_len(ogg_packet &op, void ogm_demuxer_c::process_page(int64_t granulepos) { ogg_packet op; - int64_t duration; - int duration_len; while (ogg_stream_packetout(&os, &op) == 1) { eos |= op.e_o_s; @@ -885,6 +879,8 @@ void ogm_demuxer_c::process_page(int64_t granulepos) { if (((*op.packet & 3) == PACKET_TYPE_HEADER) || ((*op.packet & 3) == PACKET_TYPE_COMMENT)) continue; + int64_t duration; + int duration_len; get_duration_and_len(op, duration, duration_len); memory_c *mem = new memory_c(&op.packet[duration_len + 1], op.bytes - 1 - duration_len, false); @@ -1104,7 +1100,7 @@ void ogm_v_avc_demuxer_c::initialize() { stream_header *sth = (stream_header *)(packet_data[0]->get() + 1); - if (video_fps < 0) + if (0 > video_fps) video_fps = 10000000.0 / (float)get_uint64_le(&sth->time_unit); } @@ -1195,7 +1191,7 @@ void ogm_v_mscomp_demuxer_c::initialize() { stream_header *sth = (stream_header *)(packet_data[0]->get() + 1); - if (video_fps < 0) + if (0 > video_fps) video_fps = 10000000.0 / (float)get_uint64_le(&sth->time_unit); default_duration = 100 * get_uint64_le(&sth->time_unit); @@ -1203,7 +1199,6 @@ ogm_v_mscomp_demuxer_c::initialize() { generic_packetizer_c * ogm_v_mscomp_demuxer_c::create_packetizer(track_info_c &ti) { - generic_packetizer_c *ptzr_obj; alBITMAPINFOHEADER bih; stream_header *sth = (stream_header *)&packet_data[0]->get()[1]; @@ -1225,6 +1220,7 @@ ogm_v_mscomp_demuxer_c::create_packetizer(track_info_c &ti) { int width = get_uint32_le(&sth->sh.video.width); int height = get_uint32_le(&sth->sh.video.height); + generic_packetizer_c *ptzr_obj; if (mpeg4::p2::is_fourcc(sth->subtype)) { ptzr_obj = new mpeg4_p2_video_packetizer_c(reader, fps, width, height, false, ti); @@ -1246,7 +1242,6 @@ ogm_v_mscomp_demuxer_c::process_page(int64_t granulepos) { vector frames; ogg_packet op; int64_t duration; - int duration_len, i; while (ogg_stream_packetout(&os, &op) == 1) { eos |= op.e_o_s; @@ -1254,6 +1249,7 @@ ogm_v_mscomp_demuxer_c::process_page(int64_t granulepos) { if (((*op.packet & 3) == PACKET_TYPE_HEADER) || ((*op.packet & 3) == PACKET_TYPE_COMMENT)) continue; + int duration_len; get_duration_and_len(op, duration, duration_len); if (!duration_len || !duration) @@ -1272,6 +1268,7 @@ ogm_v_mscomp_demuxer_c::process_page(int64_t granulepos) { if ((granulepos - last_granulepos) > frames.size()) last_granulepos = granulepos - frames.size(); + int i; for (i = 0; i < frames.size(); ++i) { ogm_frame_t &frame = frames[i]; @@ -1326,8 +1323,6 @@ ogm_v_theora_demuxer_c::create_packetizer(track_info_c &ti) { void ogm_v_theora_demuxer_c::process_page(int64_t granulepos) { - int keyframe_number, non_keyframe_number; - int64_t timecode, duration, bref; ogg_packet op; while (ogg_stream_packetout(&os, &op) == 1) { @@ -1336,13 +1331,13 @@ ogm_v_theora_demuxer_c::process_page(int64_t granulepos) { if ((0 == op.bytes) || (0 != (op.packet[0] & 0x80))) continue; - keyframe_number = granulepos >> theora.kfgshift; - non_keyframe_number = granulepos & theora.kfgshift; // TODO: seems wrong + int keyframe_number = granulepos >> theora.kfgshift; + int non_keyframe_number = granulepos & theora.kfgshift; // TODO: seems wrong // should probably be: // non_keyframe_number = granulepos - (keyframe_number << theora.kfgshift); - timecode = (int64_t)(1000000000.0 * units_processed * theora.frd / theora.frn); - duration = (int64_t)(1000000000.0 * theora.frd / theora.frn); - bref = (keyframe_number != last_keyframe_number) && (0 == non_keyframe_number) ? VFT_IFRAME : VFT_PFRAMEAUTOMATIC; + int64_t timecode = (int64_t)(1000000000.0 * units_processed * theora.frd / theora.frn); + int64_t duration = (int64_t)(1000000000.0 * theora.frd / theora.frn); + int64_t bref = (keyframe_number != last_keyframe_number) && (0 == non_keyframe_number) ? VFT_IFRAME : VFT_PFRAMEAUTOMATIC; reader->reader_packetizers[ptzr]->process(new packet_t(new memory_c(op.packet, op.bytes, false), timecode, duration, bref, VFT_NOBFRAME)); @@ -1409,9 +1404,6 @@ ogm_s_kate_demuxer_c::process_page(int64_t granulepos) { if ((0 == op.bytes) || (0 != (op.packet[0] & 0x80))) continue; -// int base = granulepos >> kate.kfgshift; -// int offset = granulepos - (base << kate.kfgshift); - reader->reader_packetizers[ptzr]->process(new packet_t(new memory_c(op.packet, op.bytes, false))); ++units_processed; diff --git a/src/input/r_ogm_flac.cpp b/src/input/r_ogm_flac.cpp index 5ac24cc06..7c64fc43a 100644 --- a/src/input/r_ogm_flac.cpp +++ b/src/input/r_ogm_flac.cpp @@ -42,10 +42,9 @@ fhe_read_cb(const FLAC__StreamDecoder *decoder, size_t *bytes, #endif void *client_data) { - flac_header_extractor_c *fhe; ogg_packet op; - fhe = (flac_header_extractor_c *)client_data; + flac_header_extractor_c *fhe = (flac_header_extractor_c *)client_data; if (fhe->done) return FLAC__STREAM_DECODER_READ_STATUS_ABORT; @@ -220,7 +219,10 @@ flac_header_extractor_c::read_page() { ogm_a_flac_demuxer_c::ogm_a_flac_demuxer_c(ogm_reader_c *p_reader): ogm_demuxer_c(p_reader), - flac_header_packets(0), sample_rate(0), channels(0), bits_per_sample(0) { + flac_header_packets(0), + sample_rate(0), + channels(0), + bits_per_sample(0) { stype = OGM_STREAM_TYPE_A_FLAC; } diff --git a/src/input/r_qtmp4.cpp b/src/input/r_qtmp4.cpp index f94e33572..fca925185 100644 --- a/src/input/r_qtmp4.cpp +++ b/src/input/r_qtmp4.cpp @@ -53,11 +53,11 @@ using namespace libmatroska; #define LE2STR(a) ((char *)&a)[0], ((char *)&a)[1], ((char *)&a)[2], ((char *)&a)[3] #endif -#define IS_AAC_OBJECT_TYPE_ID(object_type_id) \ - ((MP4OTI_MPEG4Audio == object_type_id) || \ - (MP4OTI_MPEG2AudioMain == object_type_id) || \ - (MP4OTI_MPEG2AudioLowComplexity == object_type_id) || \ - (MP4OTI_MPEG2AudioScaleableSamplingRate == object_type_id)) +#define IS_AAC_OBJECT_TYPE_ID(object_type_id) \ + ( (MP4OTI_MPEG4Audio == object_type_id) \ + || (MP4OTI_MPEG2AudioMain == object_type_id) \ + || (MP4OTI_MPEG2AudioLowComplexity == object_type_id) \ + || (MP4OTI_MPEG2AudioScaleableSamplingRate == object_type_id)) int qtmp4_reader_c::probe_file(mm_io_c *in, @@ -76,13 +76,13 @@ qtmp4_reader_c::probe_file(mm_io_c *in, mxverb(3, PFX "Atom: '%c%c%c%c'; size: " LLU "\n", BE2STR(atom), atom_size); - if ((atom == FOURCC('m', 'o', 'o', 'v')) || - (atom == FOURCC('f', 't', 'y', 'p')) || - (atom == FOURCC('m', 'd', 'a', 't')) || - (atom == FOURCC('p', 'n', 'o', 't'))) + if ( (FOURCC('m', 'o', 'o', 'v') == atom) + || (FOURCC('f', 't', 'y', 'p') == atom) + || (FOURCC('m', 'd', 'a', 't') == atom) + || (FOURCC('p', 'n', 'o', 't') == atom)) return 1; - if (atom == FOURCC('w', 'i', 'd', 'e')) + if (FOURCC('w', 'i', 'd', 'e') == atom) continue; return 0; @@ -142,11 +142,11 @@ qtmp4_reader_c::read_atom(mm_io_c *read_from, a.fourcc = read_from->read_uint32_be(); a.hsize = 8; - if (a.size == 1) { + if (1 == a.size) { a.size = read_from->read_uint64_be(); a.hsize += 8; - } else if (a.size == 0) + } else if (0 == a.size) a.size = file_size - read_from->getFilePointer() + 8; if (a.size < a.hsize) { @@ -164,18 +164,16 @@ qtmp4_reader_c::read_atom(mm_io_c *read_from, void qtmp4_reader_c::parse_headers() { uint32_t tmp, idx; - qt_atom_t atom; - bool headers_parsed; int i; io->setFilePointer(0); - headers_parsed = false; + bool headers_parsed = false; do { - atom = read_atom(); + qt_atom_t atom = read_atom(); mxverb(2, PFX "'%c%c%c%c' atom, size " LLD ", at " LLD "\n", BE2STR(atom), atom.size, atom.pos); - if (atom.fourcc == FOURCC('f', 't', 'y', 'p')) { + if (FOURCC('f', 't', 'y', 'p') == atom.fourcc) { tmp = io->read_uint32_be(); mxverb(2, PFX " File type major brand: %c%c%c%c\n", BE2STR(tmp)); tmp = io->read_uint32_be(); @@ -185,14 +183,14 @@ qtmp4_reader_c::parse_headers() { mxverb(2, PFX " File type compatible brands #%d: %c%c%c%c\n", i, BE2STR(tmp)); } - } else if (atom.fourcc == FOURCC('m', 'o', 'o', 'v')) { + } else if (FOURCC('m', 'o', 'o', 'v') == atom.fourcc) { handle_moov_atom(atom.to_parent(), 0); headers_parsed = true; - } else if (atom.fourcc == FOURCC('w', 'i', 'd', 'e')) { + } else if (FOURCC('w', 'i', 'd', 'e') == atom.fourcc) { skip_atom(); - } else if (atom.fourcc == FOURCC('m', 'd', 'a', 't')) { + } else if (FOURCC('m', 'd', 'a', 't') == atom.fourcc) { mdat_pos = io->getFilePointer(); mdat_size = atom.size; skip_atom(); @@ -212,33 +210,32 @@ qtmp4_reader_c::parse_headers() { for (idx = 0; idx < demuxers.size(); ++idx) { qtmp4_demuxer_cptr &dmx = demuxers[idx]; - if ((('v' == dmx->type) && - strncasecmp(dmx->fourcc, "SVQ", 3) && - strncasecmp(dmx->fourcc, "cvid", 4) && - strncasecmp(dmx->fourcc, "rle ", 4) && - strncasecmp(dmx->fourcc, "mp4v", 4) && - strncasecmp(dmx->fourcc, "avc1", 4)) + if (( ('v' == dmx->type) + && strncasecmp(dmx->fourcc, "SVQ", 3) + && strncasecmp(dmx->fourcc, "cvid", 4) + && strncasecmp(dmx->fourcc, "rle ", 4) + && strncasecmp(dmx->fourcc, "mp4v", 4) + && strncasecmp(dmx->fourcc, "avc1", 4)) || - (('a' == dmx->type) && - strncasecmp(dmx->fourcc, "QDM", 3) && - strncasecmp(dmx->fourcc, "MP4A", 4) && - strncasecmp(dmx->fourcc, "twos", 4) && - strncasecmp(dmx->fourcc, "swot", 4) && - strncasecmp(dmx->fourcc, "ac-3", 4))) { + ( ('a' == dmx->type) + && strncasecmp(dmx->fourcc, "QDM", 3) + && strncasecmp(dmx->fourcc, "MP4A", 4) + && strncasecmp(dmx->fourcc, "twos", 4) + && strncasecmp(dmx->fourcc, "swot", 4) + && strncasecmp(dmx->fourcc, "ac-3", 4))) { mxwarn(PFX "Unknown/unsupported FourCC '%.4s' for track %u.\n", dmx->fourcc, dmx->id); continue; } if (('a' == dmx->type) && !strncasecmp(dmx->fourcc, "MP4A", 4)) { - if (!IS_AAC_OBJECT_TYPE_ID(dmx->esds.object_type_id) && - (dmx->esds.object_type_id != MP4OTI_MPEG2AudioPart3) && // MP3... - (dmx->esds.object_type_id != MP4OTI_MPEG1Audio)) { + if ( !IS_AAC_OBJECT_TYPE_ID(dmx->esds.object_type_id) + && (MP4OTI_MPEG2AudioPart3 != dmx->esds.object_type_id) // MP3... + && (MP4OTI_MPEG1Audio != dmx->esds.object_type_id)) { mxwarn(PFX "The audio track %u is using an unsupported 'object type id' of %u in the 'esds' atom. Skipping this track.\n", dmx->id, dmx->esds.object_type_id); continue; } - if (IS_AAC_OBJECT_TYPE_ID(dmx->esds.object_type_id) && - ((NULL == dmx->esds.decoder_config) || !dmx->a_aac_config_parsed)) { + if (IS_AAC_OBJECT_TYPE_ID(dmx->esds.object_type_id) && ((NULL == dmx->esds.decoder_config) || !dmx->a_aac_config_parsed)) { mxwarn(PFX "The AAC track %u is missing the esds atom/the decoder config. Skipping this track.\n", dmx->id); continue; } @@ -259,14 +256,14 @@ qtmp4_reader_c::parse_headers() { // video. The object type ID in the ESDS tells the demuxer what // it is. So let's check for those. // If the FourCC is unmodified then MPEG4 is assumed. - if ((dmx->esds.object_type_id == MP4OTI_MPEG2VisualSimple) || - (dmx->esds.object_type_id == MP4OTI_MPEG2VisualMain) || - (dmx->esds.object_type_id == MP4OTI_MPEG2VisualSNR) || - (dmx->esds.object_type_id == MP4OTI_MPEG2VisualSpatial) || - (dmx->esds.object_type_id == MP4OTI_MPEG2VisualHigh) || - (dmx->esds.object_type_id == MP4OTI_MPEG2Visual422)) + if ( (MP4OTI_MPEG2VisualSimple == dmx->esds.object_type_id) + || (MP4OTI_MPEG2VisualMain == dmx->esds.object_type_id) + || (MP4OTI_MPEG2VisualSNR == dmx->esds.object_type_id) + || (MP4OTI_MPEG2VisualSpatial == dmx->esds.object_type_id) + || (MP4OTI_MPEG2VisualHigh == dmx->esds.object_type_id) + || (MP4OTI_MPEG2Visual422 == dmx->esds.object_type_id)) memcpy(dmx->fourcc, "mpg2", 4); - else if (dmx->esds.object_type_id == MP4OTI_MPEG1Visual) + else if (MP4OTI_MPEG1Visual == dmx->esds.object_type_id) memcpy(dmx->fourcc, "mpg1", 4); else { // This is MPEG4 video, and we need header data for it. @@ -455,10 +452,10 @@ qtmp4_reader_c::handle_cmov_atom(qt_atom_t parent, atom = read_atom(); mxverb(2, PFX "%*s'%c%c%c%c' atom, size " LLD ", at " LLD "\n", 2 * level, "", BE2STR(atom.fourcc), atom.size, atom.pos); - if (atom.fourcc == FOURCC('d', 'c', 'o', 'm')) + if (FOURCC('d', 'c', 'o', 'm') == atom.fourcc) handle_dcom_atom(atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('c', 'm', 'v', 'd')) + else if (FOURCC('c', 'm', 'v', 'd') == atom.fourcc) handle_cmvd_atom(atom.to_parent(), level + 1); skip_atom(); @@ -470,26 +467,24 @@ void qtmp4_reader_c::handle_cmvd_atom(qt_atom_t atom, int level) { #if defined(HAVE_ZLIB_H) - uint32_t moov_size, cmov_size; - unsigned char *moov_buf, *cmov_buf; - int zret; - z_stream zs; - mm_io_c *old_io; - moov_size = io->read_uint32_be(); + uint32_t moov_size = io->read_uint32_be(); mxverb(2, PFX "%*sUncompressed size: %u\n", (level + 1) * 2, "", moov_size); if (compression_algorithm != FOURCC('z', 'l', 'i', 'b')) mxerror(PFX "This file uses compressed headers with an unknown or unsupported compression algorithm '%c%c%c%c'. Aborting.\n", BE2STR(compression_algorithm)); - old_io = io; - cmov_size = atom.size - atom.hsize; - cmov_buf = (unsigned char *)safemalloc(cmov_size); - moov_buf = (unsigned char *)safemalloc(moov_size + 16); + mm_io_c *old_io = io; + uint32_t cmov_size = atom.size - atom.hsize; + memory_cptr af_cmov_buf = memory_c::alloc(cmov_size); + unsigned char *cmov_buf = af_cmov_buf->get(); + memory_cptr af_moov_buf = memory_c::alloc(moov_size + 16); + unsigned char *moov_buf = af_moov_buf->get(); if (io->read(cmov_buf, cmov_size) != cmov_size) throw error_c("end-of-file"); + z_stream zs; zs.zalloc = (alloc_func)NULL; zs.zfree = (free_func)NULL; zs.opaque = (voidpf)NULL; @@ -498,8 +493,8 @@ qtmp4_reader_c::handle_cmvd_atom(qt_atom_t atom, zs.next_out = moov_buf; zs.avail_out = moov_size; - zret = inflateInit(&zs); - if (zret != Z_OK) + int zret = inflateInit(&zs); + if (Z_OK != zret) mxerror(PFX "This file uses compressed headers, but the zlib library could not be initialized. Error code from zlib: %d. Aborting.\n", zret); zret = inflate(&zs, Z_NO_FLUSH); @@ -512,11 +507,9 @@ qtmp4_reader_c::handle_cmvd_atom(qt_atom_t atom, zret = inflateEnd(&zs); - io = new mm_mem_io_c(moov_buf, zs.total_out); + io = new mm_mem_io_c(moov_buf, zs.total_out); while (!io->eof()) { - qt_atom_t next_atom; - - next_atom = read_atom(); + qt_atom_t next_atom = read_atom(); mxverb(2, PFX "%*s'%c%c%c%c' atom at " LLD "\n", (level + 1) * 2, "", BE2STR(next_atom.fourcc), next_atom.pos); if (FOURCC('m', 'o', 'o', 'v') == next_atom.fourcc) @@ -527,9 +520,6 @@ qtmp4_reader_c::handle_cmvd_atom(qt_atom_t atom, delete io; io = old_io; - safefree(moov_buf); - safefree(cmov_buf); - #else // HAVE_ZLIB_H mxerror("mkvmerge was not compiled with zlib. Compressed headers in QuickTime/MP4 files are therefore not supported.\n"); #endif // HAVE_ZLIB_H @@ -539,12 +529,11 @@ void qtmp4_reader_c::handle_ctts_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t atom, int level) { - uint32_t count, i; - io->skip(1 + 3); // version & flags - count = io->read_uint32_be(); + uint32_t count = io->read_uint32_be(); mxverb(2, PFX "%*sFrame offset table: %u raw entries\n", level * 2, "", count); + int i; for (i = 0; i < count; ++i) { qt_frame_offset_t frame_offset; @@ -559,11 +548,8 @@ qtmp4_reader_c::handle_ctts_atom(qtmp4_demuxer_cptr &new_dmx, void qtmp4_reader_c::handle_dcom_atom(qt_atom_t atom, int level) { - uint32_t algo; - - algo = io->read_uint32_be(); - mxverb(2, PFX "%*sCompression algorithm: %c%c%c%c\n", level * 2, "", BE2STR(algo)); - compression_algorithm = algo; + compression_algorithm = io->read_uint32_be(); + mxverb(2, PFX "%*sCompression algorithm: %c%c%c%c\n", level * 2, "", BE2STR(compression_algorithm)); } void @@ -572,7 +558,7 @@ qtmp4_reader_c::handle_hdlr_atom(qtmp4_demuxer_cptr &new_dmx, int level) { hdlr_atom_t hdlr; - if (atom.size < sizeof(hdlr_atom_t)) + if (sizeof(hdlr_atom_t) > atom.size) mxerror(PFX "'hdlr' atom is too small. Expected size: >= %u. Actual size: " LLD ".\n", (unsigned int)sizeof(hdlr_atom_t), atom.size); if (io->read(&hdlr, sizeof(hdlr_atom_t)) != sizeof(hdlr_atom_t)) @@ -595,20 +581,17 @@ void qtmp4_reader_c::handle_mdhd_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t atom, int level) { - int version; - - if (atom.size < 1) + if (1 > atom.size) mxerror(PFX "'mdhd' atom is too small. Expected size: >= %u. Actual size: " LLD ".\n", (unsigned int)sizeof(mdhd_atom_t), atom.size); - version = io->read_uint8(); + int version = io->read_uint8(); if (0 == version) { mdhd_atom_t mdhd; - if (atom.size < sizeof(mdhd_atom_t)) + if (sizeof(mdhd_atom_t) > atom.size) mxerror(PFX "'mdhd' atom is too small. Expected size: >= %u. Actual size: " LLD ".\n", (unsigned int)sizeof(mdhd_atom_t), atom.size); - if (io->read(&mdhd.flags, sizeof(mdhd_atom_t) - 1) != - (sizeof(mdhd_atom_t) - 1)) + if (io->read(&mdhd.flags, sizeof(mdhd_atom_t) - 1) != (sizeof(mdhd_atom_t) - 1)) throw error_c("end-of-file"); new_dmx->time_scale = get_uint32_be(&mdhd.time_scale); @@ -619,10 +602,9 @@ qtmp4_reader_c::handle_mdhd_atom(qtmp4_demuxer_cptr &new_dmx, } else if (1 == version) { mdhd64_atom_t mdhd; - if (atom.size < sizeof(mdhd64_atom_t)) + if (sizeof(mdhd64_atom_t) > atom.size) mxerror(PFX "'mdhd' atom is too small. Expected size: >= %u. Actual size: " LLD ".\n", (unsigned int)sizeof(mdhd64_atom_t), atom.size); - if (io->read(&mdhd.flags, sizeof(mdhd64_atom_t) - 1) != - (sizeof(mdhd64_atom_t) - 1)) + if (io->read(&mdhd.flags, sizeof(mdhd64_atom_t) - 1) != (sizeof(mdhd64_atom_t) - 1)) throw error_c("end-of-file"); new_dmx->time_scale = get_uint32_be(&mdhd.time_scale); @@ -642,18 +624,16 @@ qtmp4_reader_c::handle_mdia_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t parent, int level) { while (parent.size > 0) { - qt_atom_t atom; - - atom = read_atom(); + qt_atom_t atom = read_atom(); mxverb(2, PFX "%*s'%c%c%c%c' atom, size " LLD ", at " LLD "\n", 2 * level, "", BE2STR(atom.fourcc), atom.size, atom.pos); - if (atom.fourcc == FOURCC('m', 'd', 'h', 'd')) + if (FOURCC('m', 'd', 'h', 'd') == atom.fourcc) handle_mdhd_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('h', 'd', 'l', 'r')) + else if (FOURCC('h', 'd', 'l', 'r') == atom.fourcc) handle_hdlr_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('m', 'i', 'n', 'f')) + else if (FOURCC('m', 'i', 'n', 'f') == atom.fourcc) handle_minf_atom(new_dmx, atom.to_parent(), level + 1); skip_atom(); @@ -665,16 +645,14 @@ void qtmp4_reader_c::handle_minf_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t parent, int level) { - while (parent.size > 0) { - qt_atom_t atom; - - atom = read_atom(); + while (0 < parent.size) { + qt_atom_t atom = read_atom(); mxverb(2, PFX "%*s'%c%c%c%c' atom, size " LLD ", at " LLD "\n", 2 * level, "", BE2STR(atom.fourcc), atom.size, atom.pos); - if (atom.fourcc == FOURCC('h', 'd', 'l', 'r')) + if (FOURCC('h', 'd', 'l', 'r') == atom.fourcc) handle_hdlr_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('s', 't', 'b', 'l')) + else if (FOURCC('s', 't', 'b', 'l') == atom.fourcc) handle_stbl_atom(new_dmx, atom.to_parent(), level + 1); skip_atom(); @@ -686,19 +664,17 @@ void qtmp4_reader_c::handle_moov_atom(qt_atom_t parent, int level) { while (parent.size > 0) { - qt_atom_t atom; - - atom = read_atom(); + qt_atom_t atom = read_atom(); mxverb(2, PFX "%*s'%c%c%c%c' atom, size " LLD ", at " LLD "\n", 2 * level, "", BE2STR(atom.fourcc), atom.size, atom.pos); - if (atom.fourcc == FOURCC('c', 'm', 'o', 'v')) { + if (FOURCC('c', 'm', 'o', 'v') == atom.fourcc) { compression_algorithm = 0; handle_cmov_atom(atom.to_parent(), level + 1); - } else if (atom.fourcc == FOURCC('m', 'v', 'h', 'd')) + } else if (FOURCC('m', 'v', 'h', 'd') == atom.fourcc) handle_mvhd_atom(atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('t', 'r', 'a', 'k')) { + else if (FOURCC('t', 'r', 'a', 'k') == atom.fourcc) { qtmp4_demuxer_cptr new_dmx(new qtmp4_demuxer_c); handle_trak_atom(new_dmx, atom.to_parent(), level + 1); @@ -716,7 +692,7 @@ qtmp4_reader_c::handle_mvhd_atom(qt_atom_t atom, int level) { mvhd_atom_t mvhd; - if ((atom.size - atom.hsize) < sizeof(mvhd_atom_t)) + if (sizeof(mvhd_atom_t) > (atom.size - atom.hsize)) mxerror(PFX "'mvhd' atom is too small. Expected size: >= %u. Actual size: " LLD ".\n", (unsigned int)sizeof(mvhd_atom_t), atom.size); if (io->read(&mvhd, sizeof(mvhd_atom_t)) != sizeof(mvhd_atom_t)) throw error_c("end-of-file"); @@ -730,34 +706,32 @@ void qtmp4_reader_c::handle_stbl_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t parent, int level) { - while (parent.size > 0) { - qt_atom_t atom; - - atom = read_atom(); + while (0 < parent.size) { + qt_atom_t atom = read_atom(); mxverb(2, PFX "%*s'%c%c%c%c' atom, size " LLD ", at " LLD "\n", 2 * level, "", BE2STR(atom.fourcc), atom.size, atom.pos); - if (atom.fourcc == FOURCC('s', 't', 't', 's')) + if (FOURCC('s', 't', 't', 's') == atom.fourcc) handle_stts_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('s', 't', 's', 'd')) + else if (FOURCC('s', 't', 's', 'd') == atom.fourcc) handle_stsd_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('s', 't', 's', 's')) + else if (FOURCC('s', 't', 's', 's') == atom.fourcc) handle_stss_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('s', 't', 's', 'c')) + else if (FOURCC('s', 't', 's', 'c') == atom.fourcc) handle_stsc_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('s', 't', 's', 'z')) + else if (FOURCC('s', 't', 's', 'z') == atom.fourcc) handle_stsz_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('s', 't', 'c', 'o')) + else if (FOURCC('s', 't', 'c', 'o') == atom.fourcc) handle_stco_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('c', 'o', '6', '4')) + else if (FOURCC('c', 'o', '6', '4') == atom.fourcc) handle_co64_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('c', 't', 't', 's')) + else if (FOURCC('c', 't', 't', 's') == atom.fourcc) handle_ctts_atom(new_dmx, atom.to_parent(), level + 1); skip_atom(); @@ -769,13 +743,12 @@ void qtmp4_reader_c::handle_stco_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t atom, int level) { - uint32_t count, i; - io->skip(1 + 3); // version & flags - count = io->read_uint32_be(); + uint32_t count = io->read_uint32_be(); mxverb(2, PFX "%*sChunk offset table: %u entries\n", level * 2, "", count); + int i; for (i = 0; i < count; ++i) { qt_chunk_t chunk; @@ -789,13 +762,12 @@ void qtmp4_reader_c::handle_co64_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t atom, int level) { - uint32_t count, i; - io->skip(1 + 3); // version & flags - count = io->read_uint32_be(); + uint32_t count = io->read_uint32_be(); mxverb(2, PFX "%*s64bit chunk offset table: %u entries\n", level * 2, "", count); + int i; for (i = 0; i < count; ++i) { qt_chunk_t chunk; @@ -809,10 +781,9 @@ void qtmp4_reader_c::handle_stsc_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t atom, int level) { - uint32_t count, i; - io->skip(1 + 3); // version & flags - count = io->read_uint32_be(); + uint32_t count = io->read_uint32_be(); + int i; for (i = 0; i < count; ++i) { qt_chunkmap_t chunkmap; @@ -829,30 +800,27 @@ void qtmp4_reader_c::handle_stsd_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t atom, int level) { - uint32_t count, i, size, tmp, stsd_size; - int64_t pos; - sound_v1_stsd_atom_t sv1_stsd; - video_stsd_atom_t v_stsd; - unsigned char *priv; - - stsd_size = 0; + uint32_t stsd_size = 0; io->skip(1 + 3); // version & flags - count = io->read_uint32_be(); + uint32_t count = io->read_uint32_be(); + int i; for (i = 0; i < count; ++i) { - pos = io->getFilePointer(); - size = io->read_uint32_be(); - priv = (unsigned char *)safemalloc(size); + int64_t pos = io->getFilePointer(); + uint32_t size = io->read_uint32_be(); + memory_cptr af_priv = memory_c::alloc(size); + unsigned char *priv = af_priv->get(); if (io->read(priv, size) != size) mxerror(PFX "Could not read the stream description atom for track ID %u.\n", new_dmx->id); - if (new_dmx->type == 'a') { - if (size < sizeof(sound_v0_stsd_atom_t)) + if ('a' == new_dmx->type) { + if (sizeof(sound_v0_stsd_atom_t) > size) mxerror(PFX "Could not read the sound description atom for track ID %u.\n", new_dmx->id); + sound_v1_stsd_atom_t sv1_stsd; memcpy(&sv1_stsd, priv, sizeof(sound_v0_stsd_atom_t)); - if (new_dmx->fourcc[0] != 0) + if (0 != new_dmx->fourcc[0]) mxwarn(PFX "Track ID %u has more than one FourCC. Only using the first one (%.4s) and not this one (%.4s).\n", new_dmx->id, new_dmx->fourcc, sv1_stsd.v0.base.fourcc); else memcpy(new_dmx->fourcc, sv1_stsd.v0.base.fourcc, 4); @@ -867,7 +835,7 @@ qtmp4_reader_c::handle_stsd_atom(qtmp4_demuxer_cptr &new_dmx, get_uint16_be(&sv1_stsd.v0.version)); if (get_uint16_be(&sv1_stsd.v0.version) == 1) { - if ((size < sizeof(sound_v1_stsd_atom_t)) || (io->read(&sv1_stsd.v1, sizeof(sv1_stsd.v1)) != sizeof(sv1_stsd.v1))) + if ((sizeof(sound_v1_stsd_atom_t) > size) || (io->read(&sv1_stsd.v1, sizeof(sv1_stsd.v1)) != sizeof(sv1_stsd.v1))) mxerror(PFX "Could not read the extended sound description atom for track ID %u.\n", new_dmx->id); mxverb(2, ", samples per packet: %u, bytes per packet: %u, bytes per frame: %u, bytes_per_sample: %u", @@ -880,7 +848,7 @@ qtmp4_reader_c::handle_stsd_atom(qtmp4_demuxer_cptr &new_dmx, new_dmx->a_channels = get_uint16_be(&sv1_stsd.v0.channels); new_dmx->a_bitdepth = get_uint16_be(&sv1_stsd.v0.sample_size); - tmp = get_uint32_be(&sv1_stsd.v0.sample_rate); + uint32_t tmp = get_uint32_be(&sv1_stsd.v0.sample_rate); new_dmx->a_samplerate = (float)((tmp & 0xffff0000) >> 16) + (float)(tmp & 0x0000ffff) / 65536.0; if (get_uint16_be(&sv1_stsd.v0.version) == 1) @@ -898,6 +866,7 @@ qtmp4_reader_c::handle_stsd_atom(qtmp4_demuxer_cptr &new_dmx, if (size < sizeof(video_stsd_atom_t)) mxerror(PFX "Could not read the video description atom for track ID %u.\n", new_dmx->id); + video_stsd_atom_t v_stsd; memcpy(&v_stsd, priv, sizeof(video_stsd_atom_t)); new_dmx->v_stsd = (unsigned char *)safememdup(priv, size); new_dmx->v_stsd_size = size; @@ -928,7 +897,6 @@ qtmp4_reader_c::handle_stsd_atom(qtmp4_demuxer_cptr &new_dmx, parse_audio_header_priv_atoms(new_dmx, priv + stsd_size, size - stsd_size, level); } - safefree(priv); io->setFilePointer(pos + size); } } @@ -937,11 +905,10 @@ void qtmp4_reader_c::handle_stss_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t atom, int level) { - uint32_t count, i; - io->skip(1 + 3); // version & flags - count = io->read_uint32_be(); + uint32_t count = io->read_uint32_be(); + int i; for (i = 0; i < count; ++i) new_dmx->keyframe_table.push_back(io->read_uint32_be()); @@ -954,12 +921,12 @@ void qtmp4_reader_c::handle_stsz_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t atom, int level) { - uint32_t count, i, sample_size; - io->skip(1 + 3); // version & flags - sample_size = io->read_uint32_be(); - count = io->read_uint32_be(); - if (sample_size == 0) { + uint32_t sample_size = io->read_uint32_be(); + uint32_t count = io->read_uint32_be(); + + if (0 == sample_size) { + int i; for (i = 0; i < count; ++i) { qt_sample_t sample; @@ -979,10 +946,10 @@ void qtmp4_reader_c::handle_sttd_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t atom, int level) { - uint32_t count, i; - io->skip(1 + 3); // version & flags - count = io->read_uint32_be(); + uint32_t count = io->read_uint32_be(); + + int i; for (i = 0; i < count; ++i) { qt_durmap_t durmap; @@ -998,10 +965,10 @@ void qtmp4_reader_c::handle_stts_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t atom, int level) { - uint32_t count, i; - io->skip(1 + 3); // version & flags - count = io->read_uint32_be(); + uint32_t count = io->read_uint32_be(); + + int i; for (i = 0; i < count; ++i) { qt_durmap_t durmap; @@ -1017,13 +984,11 @@ void qtmp4_reader_c::handle_edts_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t parent, int level) { - while (parent.size > 0) { - qt_atom_t atom; - - atom = read_atom(); + while (0 < parent.size) { + qt_atom_t atom = read_atom(); mxverb(2, PFX "%*s'%c%c%c%c' atom, size " LLD ", at " LLD "\n", 2 * level, "", BE2STR(atom.fourcc), atom.size, atom.pos); - if (atom.fourcc == FOURCC('e', 'l', 's', 't')) + if (FOURCC('e', 'l', 's', 't') == atom.fourcc) handle_elst_atom(new_dmx, atom.to_parent(), level + 1); skip_atom(); @@ -1035,11 +1000,11 @@ void qtmp4_reader_c::handle_elst_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t atom, int level) { - uint32_t count, i; - io->skip(1 + 3); // version & flags - count = io->read_uint32_be(); + uint32_t count = io->read_uint32_be(); new_dmx->editlist_table.resize(count); + + int i; for (i = 0; i < count; ++i) { qt_editlist_t &editlist = new_dmx->editlist_table[i]; @@ -1063,7 +1028,7 @@ qtmp4_reader_c::handle_tkhd_atom(qtmp4_demuxer_cptr &new_dmx, int level) { tkhd_atom_t tkhd; - if (atom.size < sizeof(tkhd_atom_t)) + if (sizeof(tkhd_atom_t) > atom.size) mxerror(PFX "'tkhd' atom is too small. Expected size: >= %u. Actual size: " LLD ".\n", (unsigned int)sizeof(tkhd_atom_t), atom.size); if (io->read(&tkhd, sizeof(tkhd_atom_t)) != sizeof(tkhd_atom_t)) @@ -1079,18 +1044,16 @@ qtmp4_reader_c::handle_trak_atom(qtmp4_demuxer_cptr &new_dmx, qt_atom_t parent, int level) { while (parent.size > 0) { - qt_atom_t atom; - - atom = read_atom(); + qt_atom_t atom = read_atom(); mxverb(2, PFX "%*s'%c%c%c%c' atom, size " LLD ", at " LLD "\n", 2 * level, "", BE2STR(atom.fourcc), atom.size, atom.pos); - if (atom.fourcc == FOURCC('t', 'k', 'h', 'd')) + if (FOURCC('t', 'k', 'h', 'd') == atom.fourcc) handle_tkhd_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('m', 'd', 'i', 'a')) + else if (FOURCC('m', 'd', 'i', 'a') == atom.fourcc) handle_mdia_atom(new_dmx, atom.to_parent(), level + 1); - else if (atom.fourcc == FOURCC('e', 'd', 't', 's')) + else if (FOURCC('e', 'd', 't', 's') == atom.fourcc) handle_edts_atom(new_dmx, atom.to_parent(), level + 1); skip_atom(); @@ -1113,14 +1076,13 @@ qtmp4_reader_c::read(generic_packetizer_c *ptzr, break; } - if (dmx_idx == demuxers.size()) { + if (demuxers.size() == dmx_idx) { flush_packetizers(); return FILE_STATUS_DONE; } qtmp4_demuxer_cptr &dmx = demuxers[dmx_idx]; - - qt_index_t &index = dmx->m_index[dmx->pos]; + qt_index_t &index = dmx->m_index[dmx->pos]; io->setFilePointer(index.file_pos); @@ -1128,10 +1090,11 @@ qtmp4_reader_c::read(generic_packetizer_c *ptzr, unsigned char *buffer; if (('v' == dmx->type) && (0 == dmx->pos) && !strncasecmp(dmx->fourcc, "mp4v", 4) && dmx->esds_parsed && (NULL != dmx->esds.decoder_config)) { - buffer = (unsigned char *)safemalloc(index.size + dmx->esds.decoder_config_len); - memcpy(buffer, dmx->esds.decoder_config, dmx->esds.decoder_config_len); + buffer = (unsigned char *)safemalloc(index.size + dmx->esds.decoder_config_len); buffer_offset = dmx->esds.decoder_config_len; + memcpy(buffer, dmx->esds.decoder_config, dmx->esds.decoder_config_len); + } else { buffer = (unsigned char *)safemalloc(index.size); } @@ -1157,11 +1120,10 @@ qtmp4_reader_c::read(generic_packetizer_c *ptzr, uint32_t qtmp4_reader_c::read_esds_descr_len(mm_mem_io_c &memio) { - uint32_t len, num_bytes; + uint32_t len = 0; + uint32_t num_bytes = 0; uint8_t byte; - len = 0; - num_bytes = 0; do { byte = memio.read_uint8(); len = (len << 7) | (byte & 0x7f); @@ -1176,20 +1138,15 @@ bool qtmp4_reader_c::parse_esds_atom(mm_mem_io_c &memio, qtmp4_demuxer_cptr &dmx, int level) { - uint32_t len; - uint8_t tag; - esds_t *e; - int lsp; - - lsp = (level + 1) * 2; - e = &dmx->esds; + int lsp = (level + 1) * 2; + esds_t *e = &dmx->esds; e->version = memio.read_uint8(); e->flags = memio.read_uint24_be(); mxverb(2, PFX "%*sesds: version: %u, flags: %u\n", lsp, "", e->version, e->flags); - tag = memio.read_uint8(); + uint8_t tag = memio.read_uint8(); if (MP4DT_ES == tag) { - len = read_esds_descr_len(memio); + uint32_t len = read_esds_descr_len(memio); e->esid = memio.read_uint16_be(); e->stream_priority = memio.read_uint8(); mxverb(2, PFX "%*sesds: id: %u, stream priority: %u, len: %u\n", lsp, "", e->esid, (uint32_t)e->stream_priority, len); @@ -1205,7 +1162,7 @@ qtmp4_reader_c::parse_esds_atom(mm_mem_io_c &memio, return false; } - len = read_esds_descr_len(memio); + uint32_t len = read_esds_descr_len(memio); e->object_type_id = memio.read_uint8(); e->stream_type = memio.read_uint8(); @@ -1259,8 +1216,8 @@ qtmp4_reader_c::create_bitmap_info_header(qtmp4_demuxer_cptr &dmx, const char *fourcc, int extra_size, const void *extra_data) { - int full_size = sizeof(alBITMAPINFOHEADER) + extra_size; - memory_cptr bih_p(new memory_c(safemalloc(full_size), full_size, true)); + int full_size = sizeof(alBITMAPINFOHEADER) + extra_size; + memory_cptr bih_p = memory_c::alloc(full_size); alBITMAPINFOHEADER *bih = (alBITMAPINFOHEADER *)bih_p->get(); memset(bih, 0, full_size); @@ -1312,7 +1269,6 @@ void qtmp4_reader_c::create_packetizer(int64_t tid) { uint32_t i; qtmp4_demuxer_cptr dmx; - passthrough_packetizer_c *ptzr; for (i = 0; i < demuxers.size(); ++i) if (demuxers[i]->id == tid) { @@ -1338,17 +1294,14 @@ qtmp4_reader_c::create_packetizer(int64_t tid) { mxinfo(FMT_TID "Using the MPEG-4 part 2 video output module.\n", ti.fname.c_str(), (int64_t)dmx->id); - } else if (!strncasecmp(dmx->fourcc, "mpg1", 4) || - !strncasecmp(dmx->fourcc, "mpg2", 4)) { - int version; - - version = dmx->fourcc[3] - '0'; - dmx->ptzr = add_packetizer(new mpeg1_2_video_packetizer_c(this, version, -1.0, dmx->v_width, dmx->v_height, 0, 0, false, ti)); + } else if (!strncasecmp(dmx->fourcc, "mpg1", 4) || !strncasecmp(dmx->fourcc, "mpg2", 4)) { + int version = dmx->fourcc[3] - '0'; + dmx->ptzr = add_packetizer(new mpeg1_2_video_packetizer_c(this, version, -1.0, dmx->v_width, dmx->v_height, 0, 0, false, ti)); mxinfo(FMT_TID "Using the MPEG-%d video output module.\n", ti.fname.c_str(), (int64_t)dmx->id, version); } else if (dmx->v_is_avc) { - if (dmx->frame_offset_table.size() == 0) + if (dmx->frame_offset_table.empty()) mxwarn(FMT_TID "The AVC video track is missing the 'CTTS' atom for frame timecode offsets. However, AVC/h.264 allows frames to have more than the traditional one " "(for P frames) or two (for B frames) references to other frames. The timecodes for such frames will be out-of-order, and the 'CTTS' atom is needed for " "getting the timecodes right. As it is missing the timecodes for this track might be wrong. You should watch the resulting file and make sure " @@ -1375,13 +1328,12 @@ qtmp4_reader_c::create_packetizer(int64_t tid) { } } else { - if (!strncasecmp(dmx->fourcc, "QDMC", 4) || - !strncasecmp(dmx->fourcc, "QDM2", 4)) { - ptzr = new passthrough_packetizer_c(this, ti); - dmx->ptzr = add_packetizer(ptzr); + if (!strncasecmp(dmx->fourcc, "QDMC", 4) || !strncasecmp(dmx->fourcc, "QDM2", 4)) { + passthrough_packetizer_c *ptzr = new passthrough_packetizer_c(this, ti); + dmx->ptzr = add_packetizer(ptzr); ptzr->set_track_type(track_audio); - ptzr->set_codec_id(dmx->fourcc[3] == '2' ? MKV_A_QDMC2 : MKV_A_QDMC); + ptzr->set_codec_id('2' == dmx->fourcc[3] ? MKV_A_QDMC2 : MKV_A_QDMC); ptzr->set_codec_private(dmx->priv, dmx->priv_size); ptzr->set_audio_sampling_freq(dmx->a_samplerate); ptzr->set_audio_channels(dmx->a_channels); @@ -1401,14 +1353,13 @@ qtmp4_reader_c::create_packetizer(int64_t tid) { mxinfo(FMT_TID "Using the AAC output module.\n", ti.fname.c_str(), (int64_t)dmx->id); - } else if (!strncasecmp(dmx->fourcc, "MP4A", 4) && ((dmx->esds.object_type_id == MP4OTI_MPEG2AudioPart3) || (dmx->esds.object_type_id == MP4OTI_MPEG1Audio))) { + } else if (!strncasecmp(dmx->fourcc, "MP4A", 4) && ((MP4OTI_MPEG2AudioPart3 == dmx->esds.object_type_id) || (MP4OTI_MPEG1Audio == dmx->esds.object_type_id))) { dmx->ptzr = add_packetizer(new mp3_packetizer_c(this, (int32_t)dmx->a_samplerate, dmx->a_channels, true, ti)); mxinfo(FMT_TID "Using the MPEG audio output module.\n", ti.fname.c_str(), (int64_t)dmx->id); - } else if (!strncasecmp(dmx->fourcc, "twos", 4) || - !strncasecmp(dmx->fourcc, "swot", 4)) { + } else if (!strncasecmp(dmx->fourcc, "twos", 4) || !strncasecmp(dmx->fourcc, "swot", 4)) { dmx->ptzr = add_packetizer(new pcm_packetizer_c(this, (int32_t)dmx->a_samplerate, dmx->a_channels, dmx->a_bitdepth, ti, - (dmx->a_bitdepth > 8) && (dmx->fourcc[0] == 't'))); + (8 < dmx->a_bitdepth) && ('t' == dmx->fourcc[0]))); mxinfo(FMT_TID "Using the PCM output module.\n", ti.fname.c_str(), (int64_t)dmx->id); } else if (!strncasecmp(dmx->fourcc, "ac-3", 4)) { @@ -1524,10 +1475,9 @@ qtmp4_demuxer_c::to_nsecs(int64_t value) { void qtmp4_demuxer_c::calculate_timecodes() { - int64_t timecode; int frame; - if (sample_size != 0) { + if (0 != sample_size) { for (frame = 0; chunk_table.size() > frame; ++frame) { timecodes.push_back(to_nsecs((uint64_t)chunk_table[frame].samples * (uint64_t)duration)); durations.push_back(to_nsecs((uint64_t)chunk_table[frame].size * (uint64_t)duration)); @@ -1547,9 +1497,11 @@ qtmp4_demuxer_c::calculate_timecodes() { v_dts_offset = to_nsecs(frame_offset_table[0]); for (frame = 0; sample_table.size() > frame; ++frame) { + int64_t timecode; + if (('v' == type) && !editlist_table.empty()) { int editlist_pos = 0; - int real_frame = frame; + int real_frame = frame; while (((editlist_table.size() - 1) > editlist_pos) && (frame >= editlist_table[editlist_pos + 1].start_frame)) ++editlist_pos; @@ -1590,12 +1542,11 @@ qtmp4_demuxer_c::calculate_timecodes() { } int64_t avg_duration = 0, num_good_frames = 0; - int64_t diff; for (frame = 0; timecodes_before_offsets.size() > (frame + 1); ++frame) { - diff = timecodes_before_offsets[frame + 1] - timecodes_before_offsets[frame]; + int64_t diff = timecodes_before_offsets[frame + 1] - timecodes_before_offsets[frame]; - if (diff <= 0) + if (0 >= diff) durations.push_back(0); else { ++num_good_frames; @@ -1627,13 +1578,10 @@ qtmp4_demuxer_c::adjust_timecodes(int64_t delta) { void qtmp4_demuxer_c::update_tables(int64_t global_time_scale) { - uint64_t last, s, pts; - int i, j; - - last = chunk_table.size(); + uint64_t last = chunk_table.size(); // process chunkmap: - i = chunkmap_table.size(); + int j, i = chunkmap_table.size(); while (i > 0) { --i; for (j = chunkmap_table[i].first_chunk; j < last; ++j) { @@ -1648,7 +1596,7 @@ qtmp4_demuxer_c::update_tables(int64_t global_time_scale) { } // calc pts of chunks: - s = 0; + uint64_t s = 0; for (j = 0; j < chunk_table.size(); ++j) { chunk_table[j].samples = s; s += chunk_table[j].size; @@ -1677,8 +1625,8 @@ qtmp4_demuxer_c::update_tables(int64_t global_time_scale) { } // calc pts: - s = 0; - pts = 0; + s = 0; + uint64_t pts = 0; for (j = 0; j < durmap_table.size(); ++j) { for (i = 0; i < durmap_table[j].number; ++i) { @@ -1779,7 +1727,8 @@ qtmp4_demuxer_c::is_keyframe(int frame) { if (keyframe_table.empty()) return true; - for (int kf_idx = 0; kf_idx < keyframe_table.size(); ++kf_idx) + int kf_idx; + for (kf_idx = 0; kf_idx < keyframe_table.size(); ++kf_idx) if (keyframe_table[kf_idx] == (frame + 1)) return true; @@ -1801,13 +1750,13 @@ qtmp4_demuxer_c::build_index_constant_sample_size_mode() { for (frame_idx = 0; frame_idx < chunk_table.size(); ++frame_idx) { int64_t frame_size; - if (sample_size != 1) { + if (1 != sample_size) { frame_size = chunk_table[frame_idx].size * sample_size; } else { frame_size = chunk_table[frame_idx].size; - if (type == 'a') { + if ('a' == type) { if (get_uint16_be(&a_stsd.v0.version) == 1) { frame_size *= get_uint32_be(&a_stsd.v1.bytes_per_frame); frame_size /= get_uint32_be(&a_stsd.v1.samples_per_packet); @@ -1852,4 +1801,3 @@ qtmp4_demuxer_c::read_first_bytes(memory_cptr &buf, return 0 == num_bytes; } - diff --git a/src/input/r_qtmp4.h b/src/input/r_qtmp4.h index 5bc0d092e..cf6a8b00f 100644 --- a/src/input/r_qtmp4.h +++ b/src/input/r_qtmp4.h @@ -34,7 +34,9 @@ struct qt_durmap_t { uint32_t duration; qt_durmap_t(): - number(0), duration(0) {} + number(0), + duration(0) { + } }; struct qt_chunk_t { @@ -44,7 +46,11 @@ struct qt_chunk_t { uint64_t pos; qt_chunk_t(): - samples(0), size(0), desc(0), pos(0) {} + samples(0), + size(0), + desc(0), + pos(0) { + } }; struct qt_chunkmap_t { @@ -53,7 +59,10 @@ struct qt_chunkmap_t { uint32_t sample_description_id; qt_chunkmap_t(): - first_chunk(0), samples_per_chunk(0), sample_description_id(0) {} + first_chunk(0), + samples_per_chunk(0), + sample_description_id(0) { + } }; struct qt_editlist_t { @@ -63,11 +72,17 @@ struct qt_editlist_t { uint32_t frames; uint64_t start_sample; uint64_t start_frame; - int64_t pts_offset; + int64_t pts_offset; qt_editlist_t(): - duration(0), pos(0), speed(0), frames(0), - start_sample(0), start_frame(0), pts_offset(0) {} + duration(0), + pos(0), + speed(0), + frames(0), + start_sample(0), + start_frame(0), + pts_offset(0) { + } }; struct qt_sample_t { @@ -76,7 +91,10 @@ struct qt_sample_t { uint64_t pos; qt_sample_t(): - pts(0), size(0), pos(0) {} + pts(0), + size(0), + pos(0) { + } }; struct qt_frame_offset_t { @@ -84,7 +102,9 @@ struct qt_frame_offset_t { uint32_t offset; qt_frame_offset_t(): - count(0), offset(0) {} + count(0), + offset(0) { + } }; struct qt_index_t { @@ -154,18 +174,34 @@ struct qtmp4_demuxer_c { int ptzr; qtmp4_demuxer_c(): - ok(false), type('?'), id(0), pos(0), - time_scale(1), global_duration(0), //avg_duration(0), + ok(false), + type('?'), + id(0), + pos(0), + time_scale(1), + global_duration(0), //avg_duration(0), sample_size(0), - duration(0), min_timecode(0), max_timecode(0), fps(0.0), + duration(0), + min_timecode(0), + max_timecode(0), + fps(0.0), esds_parsed(false), - v_stsd(NULL), v_stsd_size(0), - v_width(0), v_height(0), v_bitdepth(0), - v_is_avc(false), avc_use_bframes(false), - a_channels(0), a_bitdepth(0), a_samplerate(0.0), - a_aac_profile(0), a_aac_output_sample_rate(0), - a_aac_is_sbr(false), a_aac_config_parsed(false), - priv(NULL), priv_size(0), + v_stsd(NULL), + v_stsd_size(0), + v_width(0), + v_height(0), + v_bitdepth(0), + v_is_avc(false), + avc_use_bframes(false), + a_channels(0), + a_bitdepth(0), + a_samplerate(0.0), + a_aac_profile(0), + a_aac_output_sample_rate(0), + a_aac_is_sbr(false), + a_aac_config_parsed(false), + priv(NULL), + priv_size(0), warning_printed(false), ptzr(-1) { @@ -208,14 +244,17 @@ struct qt_atom_t { uint32_t hsize; qt_atom_t(): - fourcc(0), size(0), pos(0), hsize(0) {} + fourcc(0), + size(0), + pos(0), + hsize(0) {} qt_atom_t to_parent() { qt_atom_t parent; parent.fourcc = fourcc; - parent.size = size - hsize; - parent.pos = pos + hsize; + parent.size = size - hsize; + parent.pos = pos + hsize; return parent; } }; diff --git a/src/input/r_real.h b/src/input/r_real.h index d821cb1de..abd16819c 100644 --- a/src/input/r_real.h +++ b/src/input/r_real.h @@ -62,17 +62,31 @@ struct real_demuxer_t { vector segments; real_demuxer_t(rmff_track_t *n_track): - ptzr(-1), track(n_track), - bsid(0), channels(0), samples_per_second(0), bits_per_sample(0), - width(0), height(0), - is_aac(false), rv_dimensions(false), - force_keyframe_flag(false), cook_audio_fix(false), + ptzr(-1), + track(n_track), + bsid(0), + channels(0), + samples_per_second(0), + bits_per_sample(0), + width(0), + height(0), + is_aac(false), + rv_dimensions(false), + force_keyframe_flag(false), + cook_audio_fix(false), fps(0.0), - rvp(NULL), ra4p(NULL), ra5p(NULL), - private_data(NULL), extra_data(NULL), - private_size(0), extra_data_size(0), - first_frame(true), num_packets(0), - last_timecode(0), ref_timecode(0) { + rvp(NULL), + ra4p(NULL), + ra5p(NULL), + private_data(NULL), + extra_data(NULL), + private_size(0), + extra_data_size(0), + first_frame(true), + num_packets(0), + last_timecode(0), + ref_timecode(0) { + memset(fourcc, 0, 5); }; }; @@ -102,19 +116,14 @@ public: protected: virtual void parse_headers(); virtual real_demuxer_cptr find_demuxer(int id); - virtual void assemble_video_packet(real_demuxer_cptr dmx, - rmff_frame_t *frame); + virtual void assemble_video_packet(real_demuxer_cptr dmx, rmff_frame_t *frame); virtual file_status_e finish(); - virtual bool get_rv_dimensions(unsigned char *buf, int size, uint32_t &width, - uint32_t &height); - virtual void set_dimensions(real_demuxer_cptr dmx, unsigned char *buffer, - int size); + virtual bool get_rv_dimensions(unsigned char *buf, int size, uint32_t &width, uint32_t &height); + virtual void set_dimensions(real_demuxer_cptr dmx, unsigned char *buffer, int size); virtual void get_information_from_data(); virtual void deliver_aac_frames(real_demuxer_cptr dmx, memory_c &mem); - virtual void queue_audio_frames(real_demuxer_cptr dmx, memory_c &mem, - uint64_t timecode, uint32_t flags); - virtual void queue_one_audio_frame(real_demuxer_cptr dmx, memory_c &mem, - uint64_t timecode, uint32_t flags); + virtual void queue_audio_frames(real_demuxer_cptr dmx, memory_c &mem, uint64_t timecode, uint32_t flags); + virtual void queue_one_audio_frame(real_demuxer_cptr dmx, memory_c &mem, uint64_t timecode, uint32_t flags); virtual void deliver_audio_frames(real_demuxer_cptr dmx, uint64_t duration); }; diff --git a/src/input/r_ssa.h b/src/input/r_ssa.h index c12a3c793..3692b7a0b 100644 --- a/src/input/r_ssa.h +++ b/src/input/r_ssa.h @@ -63,12 +63,8 @@ protected: virtual int64_t parse_time(string &time); virtual string get_element(const char *index, vector &fields); virtual string recode_text(vector &fields); - virtual void add_attachment_maybe(string &name, string &data_uu, - ssa_section_e section); - virtual void decode_chars(unsigned char c1, unsigned char c2, - unsigned char c3, unsigned char c4, - buffer_t &buffer, int bytes_to_add, - int &allocated); + virtual void add_attachment_maybe(string &name, string &data_uu, ssa_section_e section); + virtual void decode_chars(unsigned char c1, unsigned char c2, unsigned char c3, unsigned char c4, buffer_t &buffer, int bytes_to_add, int &allocated); }; #endif // __R_SSA_H diff --git a/src/input/r_usf.h b/src/input/r_usf.h index 80fdf7cb4..37982cf47 100644 --- a/src/input/r_usf.h +++ b/src/input/r_usf.h @@ -33,10 +33,15 @@ struct usf_entry_t { string m_text; usf_entry_t(): - m_start(-1), m_end(-1) { } + m_start(-1), + m_end(-1) { + } usf_entry_t(int64_t start, int64_t end, const string &text): - m_start(start), m_end(end), m_text(text) { } + m_start(start), + m_end(end), + m_text(text) { + } bool operator <(const usf_entry_t &cmp) const { return m_start < cmp.m_start; @@ -51,7 +56,8 @@ struct usf_track_t { vector::const_iterator m_current_entry; usf_track_t(): - m_ptzr(-1) { } + m_ptzr(-1) { + } }; class usf_reader_c: public generic_reader_c, public xml_parser_c { diff --git a/src/input/r_vobsub.h b/src/input/r_vobsub.h index e86391d1f..257fddbd5 100644 --- a/src/input/r_vobsub.h +++ b/src/input/r_vobsub.h @@ -46,9 +46,13 @@ public: public: vobsub_track_c(const string &new_language): language(new_language), - ptzr(-1), idx(0), aid(-1), + ptzr(-1), + idx(0), + aid(-1), mpeg_version_warning_printed(false), - packet_num(0), spu_size(0), overhead(0) { + packet_num(0), + spu_size(0), + overhead(0) { } }; @@ -78,9 +82,7 @@ public: protected: virtual void parse_headers(); virtual void flush_packetizers(); - virtual int deliver_packet(unsigned char *buf, int size, - int64_t timecode, int64_t default_duration, - generic_packetizer_c *ptzr); + virtual int deliver_packet(unsigned char *buf, int size, int64_t timecode, int64_t default_duration, generic_packetizer_c *ptzr); virtual int extract_one_spu_packet(int64_t track_id); }; diff --git a/src/input/r_wav.h b/src/input/r_wav.h index 7fdf396b7..f07b4d0a7 100644 --- a/src/input/r_wav.h +++ b/src/input/r_wav.h @@ -41,7 +41,9 @@ public: public: wav_demuxer_c(wav_reader_c *reader, wave_header *wheader): - m_reader(reader), m_wheader(wheader), m_ptzr(NULL) { + m_reader(reader), + m_wheader(wheader), + m_ptzr(NULL) { }; virtual ~wav_demuxer_c() {};