bool readReference(IBitStream& bstr, unsigned& reference, unsigned huffmanNumber) { int code = bstr.read(2); if (code == 3) { reference = bstr.read(32); return true; } int bitlen = BitLength(huffmanNumber); assert(bitlen >= 2); reference = (code << (bitlen - 2)) | bstr.read(bitlen - 2); return true; }
bool LPCMStream::Probe(IBitStream &bs ) { char *last_dot = strrchr( bs.StreamName(), '.' ); return last_dot != NULL && strcmp( last_dot+1, "lpcm") == 0; }
std::u16string DictionaryReader::decodeArticle(IBitStream &bstr, unsigned reference) { loadDecoder(); bstr.seek(header().articlesOffset + reference); std::u16string body; bool res = decoder()->DecodeArticle(&bstr, body); if (!res) throw std::runtime_error("can't decode article"); return body; }
void LenTable::Read(IBitStream &bitstr) { symidx2nodeidx.clear(); nodes.clear(); int count = bitstr.read(32); int bitsPerLen = bitstr.read(8); int idxBitSize = BitLength(count); symidx2nodeidx.resize(count); for (unsigned& nodeIdx : symidx2nodeidx) { nodeIdx = -1; // in case the root has a leaf as a child } nodes.resize(count - 1); int rootIdx = nodes.size() - 1; nodes.at(rootIdx) = {0,0,-1,-1}; nextNodePosition = 0; for (int i = 0; i < count; ++i) { int symidx = bitstr.read(idxBitSize); int len = bitstr.read(bitsPerLen); placeSymidx(symidx, rootIdx, len); } }
std::vector<ArticleHeading> collectHeadingFromPage(IBitStream& bstr, DictionaryReader& reader, unsigned pageNumber) { std::vector<ArticleHeading> res; bstr.seek(reader.header().pagesOffset + 512 * pageNumber); CachePage page; page.loadHeader(bstr); if (page.isLeaf()) { std::u16string prefix; for (size_t idx = 0; idx < page.headingsCount(); ++idx) { ArticleHeading h; h.Load(*reader.decoder(), bstr, prefix); res.push_back(h); } } return res; }
int LenTable::Decode(IBitStream &bitstr, unsigned &symIdx) const { const HuffmanNode* node = &nodes.back(); int len = 0; for (;;) { len++; int bit = bitstr.read(1); if (bit) { // right if (node->right < 0) { // leaf symIdx = -1 - node->right; return len; } node = &nodes.at(node->right - 1); } else { // left if (node->left < 0) { // leaf symIdx = -1 - node->left; return len; } node = &nodes.at(node->left - 1); } } // unreachable }
bool DTSStream::Probe(IBitStream &bs ) { return bs.GetBits(32) == DTS_SYNCWORD; }
void MultiplexJob::SetupInputStreams( std::vector< IBitStream *> &inputs ) { IBitStream *bs; IBitStreamUndo undo; unsigned int i; bool bad_file = false; for( i = 0; i < inputs.size(); ++i ) { bs = inputs[i]; // Remember the streams initial state... bs->PrepareUndo( undo ); if( LPCMStream::Probe( *bs ) ) { mjpeg_info ("File %s looks like an LPCM Audio stream.", bs->StreamName()); bs->UndoChanges( undo ); streams.push_back( new JobStream( bs, LPCM_AUDIO) ); ++audio_tracks; ++lpcm_tracks; continue; } bs->UndoChanges( undo ); if( MPAStream::Probe( *bs ) ) { mjpeg_info ("File %s looks like an MPEG Audio stream.", bs->StreamName() ); bs->UndoChanges( undo ); streams.push_back( new JobStream( bs, MPEG_AUDIO) ); ++audio_tracks; continue; } bs->UndoChanges( undo ); if( AC3Stream::Probe( *bs ) ) { mjpeg_info ("File %s looks like an AC3 Audio stream.", bs->StreamName()); bs->UndoChanges( undo ); streams.push_back( new JobStream( bs, AC3_AUDIO) ); ++audio_tracks; continue; } bs->UndoChanges( undo ); if( DTSStream::Probe( *bs ) ) { mjpeg_info ("File %s looks like a dts Audio stream.", bs->StreamName()); bs->UndoChanges( undo); streams.push_back( new JobStream( bs, DTS_AUDIO) ); ++audio_tracks; continue; } bs->UndoChanges( undo ); if( VideoStream::Probe( *bs ) ) { mjpeg_info ("File %s looks like an MPEG Video stream.", bs->StreamName()); bs->UndoChanges( undo ); streams.push_back( new JobStream( bs, MPEG_VIDEO) ); ++video_tracks; continue; } bs->UndoChanges( undo ); if( SUBPStream::Probe( *bs ) ) { mjpeg_info ("File %s looks like an Subpicture stream.", bs->StreamName()); bs->UndoChanges( undo ); streams.push_back( new JobStream( bs, SUBP_STREAM) ); ++subtitle_tracks; continue; } #ifdef ZALPHA if( ZAlphaStream::Probe( *bs ) ) { mjpeg_info ("File %s looks like an Z/Alpha Video stream.", bs->StreamName()); bs->UndoChanges( undo ); streams.push_back( new JobStream( bs, Z_ALPHA) ); ++video_tracks; ++z_alpha_tracks; continue; } #endif bad_file = true; mjpeg_error ("File %s unrecogniseable!", bs->StreamName()); delete bs; } if( bad_file ) { mjpeg_error_exit1( "Unrecogniseable file(s)... exiting."); } // // Where no parameters for streams have been specified // simply set the default values (these will depend on the format // we're muxing of course...) // for( i = video_param.size(); i < video_tracks; ++i ) { video_param.push_back(VideoParams::Default( mux_format )); } for( i = lpcm_param.size(); i < lpcm_tracks; ++i ) { lpcm_param.push_back(LpcmParams::Default(mux_format)); } for( i = subtitle_params.size(); i < subtitle_tracks; ++i ) { subtitle_params.push_back(SubtitleStreamParams::Default(mux_format)); } // // Set standard values if the selected profile implies this... // for( i = 0; i <video_tracks; ++i ) { if( video_param[i]->Force(mux_format) ) { mjpeg_info( "Video stream %d: profile %d selected - ignoring non-standard options!", i, mux_format ); } } mjpeg_info( "Found %d audio streams, %d video streams and %d subtitle streams", audio_tracks, video_tracks, subtitle_tracks ); }
bool MPAStream::Probe(IBitStream &bs ) { return bs.GetBits(11) == AUDIO_SYNCWORD; }
bool VideoStream::Probe(IBitStream &bs ) { return bs.GetBits( 32) == 0x1b3; }