From 01c564ed78ef5c8cb1c12100da502ecee172cf60 Mon Sep 17 00:00:00 2001 From: jcdr428 Date: Wed, 9 Aug 2023 21:07:11 +0100 Subject: [PATCH] movDemuxer: change C cast to C++ cast --- tsMuxer/aac.cpp | 2 +- tsMuxer/aac.h | 2 +- tsMuxer/ac3Codec.cpp | 4 ++-- tsMuxer/ioContextDemuxer.h | 2 +- tsMuxer/movDemuxer.cpp | 41 +++++++++++++++++++------------------- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/tsMuxer/aac.cpp b/tsMuxer/aac.cpp index 2667db5d..3ee8b2b5 100644 --- a/tsMuxer/aac.cpp +++ b/tsMuxer/aac.cpp @@ -71,7 +71,7 @@ bool AACCodec::decodeFrame(uint8_t* buffer, uint8_t* end) } } -void AACCodec::buildADTSHeader(uint8_t* buffer, const int frameSize) +void AACCodec::buildADTSHeader(uint8_t* buffer, const unsigned frameSize) { BitStreamWriter writer{}; writer.setBuffer(buffer, buffer + AAC_HEADER_LEN); diff --git a/tsMuxer/aac.h b/tsMuxer/aac.h index e7cc645d..87e556a0 100644 --- a/tsMuxer/aac.h +++ b/tsMuxer/aac.h @@ -26,7 +26,7 @@ class AACCodec static uint8_t* findAacFrame(uint8_t* buffer, uint8_t* end); static int getFrameSize(uint8_t* buffer); bool decodeFrame(uint8_t* buffer, uint8_t* end); - void buildADTSHeader(uint8_t* buffer, int frameSize); + void buildADTSHeader(uint8_t* buffer, unsigned frameSize); inline void setSampleRate(int value) { m_sample_rate = value; } void readConfig(uint8_t* buff, int size); diff --git a/tsMuxer/ac3Codec.cpp b/tsMuxer/ac3Codec.cpp index b5489db4..b933857f 100644 --- a/tsMuxer/ac3Codec.cpp +++ b/tsMuxer/ac3Codec.cpp @@ -90,7 +90,7 @@ AC3Codec::AC3ParseError AC3Codec::parseHeader(uint8_t *buf, uint8_t *end) return AC3ParseError::SYNC; // read ahead to bsid to make sure this is AC-3, not E-AC-3 - const int id = buf[3] >> 3; + const uint8_t id = buf[3] >> 3; if (id > 16) return AC3ParseError::BSID; @@ -99,7 +99,7 @@ AC3Codec::AC3ParseError AC3Codec::parseHeader(uint8_t *buf, uint8_t *end) // ---------------------------------- EAC3 ------------------------------------------ if (m_bsid > 10) { - m_frame_size = (((buf[0] & 0x07) << 8 | buf[1]) + 1) << 1; + m_frame_size = static_cast((((buf[0] & 0x07) << 8 | buf[1]) + 1) << 1); if (m_frame_size < AC3_HEADER_SIZE) return AC3ParseError::FRAME_SIZE; // invalid header size diff --git a/tsMuxer/ioContextDemuxer.h b/tsMuxer/ioContextDemuxer.h index c93a240c..98227bce 100644 --- a/tsMuxer/ioContextDemuxer.h +++ b/tsMuxer/ioContextDemuxer.h @@ -54,7 +54,7 @@ struct Track encodingAlgo = 0; type = IOContextTrackType::UNDEFINED; } - ~Track() + virtual ~Track() { delete[] name; delete[] codec_id; diff --git a/tsMuxer/movDemuxer.cpp b/tsMuxer/movDemuxer.cpp index dff0ead6..6dcc371b 100644 --- a/tsMuxer/movDemuxer.cpp +++ b/tsMuxer/movDemuxer.cpp @@ -73,7 +73,7 @@ int ff_mov_lang_to_iso639(unsigned code, char* to) { for (int i = 2; i >= 0; i--) { - to[i] = 0x60 + (code & 0x1f); + to[i] = static_cast(0x60 + (code & 0x1f)); code >>= 5; } return 1; @@ -87,7 +87,7 @@ int ff_mov_lang_to_iso639(unsigned code, char* to) return 1; } -struct MOVStreamContext : public Track +struct MOVStreamContext : Track { MOVStreamContext() : m_indexCur(0), @@ -114,7 +114,8 @@ struct MOVStreamContext : public Track sample_rate(0) { } - virtual ~MOVStreamContext() {} + + ~MOVStreamContext() override {} vector chunk_offsets; vector m_index; @@ -177,7 +178,7 @@ class MovParsedAudioTrackData : public ParsedTrackPrivData const uint8_t* srcEnd = buff + size; while (buff < srcEnd - 4) { - int frameSize = m_sc->sample_size; + unsigned frameSize = m_sc->sample_size; if (frameSize == 0) frameSize = m_sc->m_index[m_sc->m_indexCur++]; if (isAAC) @@ -728,7 +729,7 @@ void MovDemuxer::buildIndex() m_curChunk = 0; chunks.clear(); - if (num_tracks == 1 && ((MOVStreamContext*)(tracks[0]))->chunk_offsets.empty()) + if (num_tracks == 1 && (dynamic_cast(tracks[0]))->chunk_offsets.empty()) { chunks.push_back(make_pair(0, 0)); } @@ -736,7 +737,7 @@ void MovDemuxer::buildIndex() { for (int i = 0; i < num_tracks; ++i) { - const auto st = (MOVStreamContext*)(tracks[i]); + const auto st = dynamic_cast(tracks[i]); for (const auto& j : st->chunk_offsets) { if (!found_moof) @@ -810,7 +811,7 @@ int MovDemuxer::simpleDemuxBlock(DemuxedData& demuxedData, const PIDSet& accepte else if (chunkSize) { MemoryBlock& vect = demuxedData[trackId + 1ll]; - const auto st = (MOVStreamContext*)(tracks[trackId]); + const auto st = dynamic_cast(tracks[trackId]); const int64_t oldSize = vect.size(); if (st->parsed_priv_data) { @@ -1084,7 +1085,7 @@ int MovDemuxer::mov_read_trun(MOVAtom atom) if (!frag->track_id || frag->track_id > num_tracks) return -1; Track* st = tracks[frag->track_id - 1]; - const auto sc = (MOVStreamContext*)(st); + const auto sc = dynamic_cast(st); if (sc->pseudo_stream_id + 1 != frag->stsd_id) return 0; get_byte(); // version @@ -1135,7 +1136,7 @@ int MovDemuxer::mov_read_trex(MOVAtom atom) MOVTrackExt& trex = trex_data[trex_data.size() - 1]; get_byte(); // version get_be24(); // flags - trex.track_id = get_be32(); + tr = get_be32(); trex.stsd_id = get_be32(); trex.duration = get_be32(); trex.size = get_be32(); @@ -1193,7 +1194,7 @@ int MovDemuxer::mov_read_tkhd(MOVAtom atom) { return 0; } int MovDemuxer::mov_read_ctts(MOVAtom atom) { - const auto st = (MOVStreamContext*)(tracks[num_tracks - 1]); + const auto st = dynamic_cast(tracks[num_tracks - 1]); get_byte(); // version get_be24(); // flags const int entries = get_be32(); @@ -1209,7 +1210,7 @@ int MovDemuxer::mov_read_ctts(MOVAtom atom) int MovDemuxer::mov_read_stts(MOVAtom atom) { - const auto st = (MOVStreamContext*)(tracks[num_tracks - 1]); + const auto st = dynamic_cast(tracks[num_tracks - 1]); get_byte(); // version get_be24(); // flags const int entries = get_be32(); @@ -1230,7 +1231,7 @@ int MovDemuxer::mov_read_stts(MOVAtom atom) int MovDemuxer::mov_read_stsz(MOVAtom atom) { - const auto st = (MOVStreamContext*)(tracks[num_tracks - 1]); + const auto st = dynamic_cast(tracks[num_tracks - 1]); get_byte(); // version get_be24(); // flags st->sample_size = get_be32(); @@ -1245,7 +1246,7 @@ int MovDemuxer::mov_read_stsz(MOVAtom atom) int MovDemuxer::mov_read_stss(MOVAtom atom) { - const auto st = (MOVStreamContext*)(tracks[num_tracks - 1]); + const auto st = dynamic_cast(tracks[num_tracks - 1]); get_byte(); // version get_be24(); // flags @@ -1339,7 +1340,7 @@ int MovDemuxer::mov_read_mdhd(MOVAtom atom) { if (num_tracks == -1) return -1; - const auto st = (MOVStreamContext*)(tracks[num_tracks - 1]); + const auto st = dynamic_cast(tracks[num_tracks - 1]); const int version = get_byte(); if (version > 1) return -1; // unsupported @@ -1371,7 +1372,7 @@ int MovDemuxer::mov_read_stsd(MOVAtom atom) { if (num_tracks == -1) return -1; - const auto st = (MOVStreamContext*)(tracks[num_tracks - 1]); + const auto st = dynamic_cast(tracks[num_tracks - 1]); get_byte(); // version get_be24(); // flags @@ -1546,7 +1547,7 @@ if (bits_per_sample) { int MovDemuxer::mov_read_stco(const MOVAtom atom) { - const auto sc = (MOVStreamContext*)(tracks[num_tracks - 1]); + const auto sc = dynamic_cast(tracks[num_tracks - 1]); get_byte(); // version get_be24(); // flags @@ -1628,7 +1629,7 @@ int MovDemuxer::mp4_read_descr(int* tag) int MovDemuxer::mov_read_esds(MOVAtom atom) { - const auto st = (MOVStreamContext*)(tracks[num_tracks - 1]); + const auto st = dynamic_cast(tracks[num_tracks - 1]); get_be32(); // version + flags int tag; mp4_read_descr(&tag); // len @@ -1666,7 +1667,7 @@ int MovDemuxer::mov_read_esds(MOVAtom atom) int MovDemuxer::mov_read_dref(MOVAtom atom) { /* - MOVStreamContext* st = (MOVStreamContext*) tracks[num_tracks-1]; + MOVStreamContext* st = dynamic_cast tracks[num_tracks-1]; get_be32(); // version + flags int entries = get_be32(); st->drefs.resize(entries); @@ -1686,7 +1687,7 @@ for (int i = 0; i < entries; i++) { } int MovDemuxer::mov_read_stsc(MOVAtom atom) { - const auto st = (MOVStreamContext*)(tracks[num_tracks - 1]); + const auto st = dynamic_cast(tracks[num_tracks - 1]); get_byte(); // version get_be24(); // flags @@ -1758,7 +1759,7 @@ int MovDemuxer::mov_read_elst(MOVAtom atom) double MovDemuxer::getTrackFps(const uint32_t trackId) { - const auto st = (MOVStreamContext*)(tracks[trackId - 1]); + const auto st = dynamic_cast(tracks[trackId - 1]); return st->fps; }