コード例 #1
0
ファイル: Ap4File.cpp プロジェクト: huangyt/MyProjects
/*----------------------------------------------------------------------
|   AP4_File::AP4_File
+---------------------------------------------------------------------*/
AP4_File::AP4_File(AP4_ByteStream&  stream, 
                   AP4_AtomFactory& atom_factory,
                   bool             moov_only) :
    m_Movie(NULL),
    m_FileType(NULL),
    m_MetaData(NULL),
    m_MoovIsBeforeMdat(true)
{
    // parse top-level atoms
    AP4_Atom*    atom;
    AP4_Position stream_position;
    bool         keep_parsing = true;
    while (keep_parsing &&
           AP4_SUCCEEDED(stream.Tell(stream_position)) && 
           AP4_SUCCEEDED(atom_factory.CreateAtomFromStream(stream, atom))) {
        AddChild(atom);
        switch (atom->GetType()) {
            case AP4_ATOM_TYPE_MOOV:
                m_Movie = new AP4_Movie(AP4_DYNAMIC_CAST(AP4_MoovAtom, atom), stream, false);
                if (moov_only) keep_parsing = false;
                break;

            case AP4_ATOM_TYPE_FTYP:
                m_FileType = AP4_DYNAMIC_CAST(AP4_FtypAtom, atom);
                break;

            case AP4_ATOM_TYPE_MDAT:
                // see if we are before the moov atom
                if (m_Movie == NULL) m_MoovIsBeforeMdat = false;
                break;
        }
    }
}
コード例 #2
0
ファイル: Ap4TrakAtom.cpp プロジェクト: olegloa/wkrj
/*----------------------------------------------------------------------
|   AP4_TrakAtom::GetChunkOffsets
+---------------------------------------------------------------------*/
AP4_Result
AP4_TrakAtom::GetChunkOffsets(AP4_Array<AP4_UI64>& chunk_offsets)
{
    AP4_Atom* atom;
    if ((atom = FindChild("mdia/minf/stbl/stco"))) {
        AP4_StcoAtom* stco = AP4_DYNAMIC_CAST(AP4_StcoAtom, atom);
        if (stco == NULL) return AP4_ERROR_INTERNAL;
        AP4_Cardinal    stco_chunk_count   = stco->GetChunkCount();
        const AP4_UI32* stco_chunk_offsets = stco->GetChunkOffsets();
        chunk_offsets.SetItemCount(stco_chunk_count);
        for (unsigned int i=0; i<stco_chunk_count; i++) {
            chunk_offsets[i] = stco_chunk_offsets[i];
        }
        return AP4_SUCCESS;
    } else if ((atom = FindChild("mdia/minf/stbl/co64"))) {
        AP4_Co64Atom* co64 = AP4_DYNAMIC_CAST(AP4_Co64Atom, atom);
        if (co64 == NULL) return AP4_ERROR_INTERNAL;
        AP4_Cardinal    co64_chunk_count   = co64->GetChunkCount();
        const AP4_UI64* co64_chunk_offsets = co64->GetChunkOffsets();
        chunk_offsets.SetItemCount(co64_chunk_count);
        for (unsigned int i=0; i<co64_chunk_count; i++) {
            chunk_offsets[i] = co64_chunk_offsets[i];
        }
        return AP4_SUCCESS;
    } else {
        return AP4_ERROR_INVALID_STATE;
    }
}
コード例 #3
0
    virtual TrackHandler* CreateTrackHandler(AP4_TrakAtom* trak) {
        // find the stsd atom
        AP4_StsdAtom* stsd = AP4_DYNAMIC_CAST(AP4_StsdAtom, trak->FindChild("mdia/minf/stbl/stsd"));

        // avoid tracks with no stsd atom (should not happen)
        if (stsd == NULL) return NULL;

        // we only look at the first sample description
        AP4_SampleDescription* desc = stsd->GetSampleDescription(0);
        AP4_MpegAudioSampleDescription* audio_desc = 
            AP4_DYNAMIC_CAST(AP4_MpegAudioSampleDescription, desc);
        if (audio_desc && audio_desc->GetObjectTypeId()==AP4_OTI_MPEG2_AAC_AUDIO_LC) {
            // patch the stsd
            AP4_MpegAudioSampleDescription new_audio_desc(AP4_OTI_MPEG4_AUDIO,
                                                          audio_desc->GetSampleRate(), 
                                                          audio_desc->GetSampleSize(),
                                                          audio_desc->GetChannelCount(),
                                                          &audio_desc->GetDecoderInfo(),
                                                          audio_desc->GetBufferSize(),
                                                          audio_desc->GetMaxBitrate(),
                                                          audio_desc->GetAvgBitrate());
            stsd->RemoveChild(stsd->GetChild(AP4_ATOM_TYPE_MP4A));
            stsd->AddChild(new_audio_desc.ToAtom());
            printf("audio sample description patched\n");
        }
        return NULL;
    }
コード例 #4
0
ファイル: Ap4TrakAtom.cpp プロジェクト: olegloa/wkrj
/*----------------------------------------------------------------------
|   AP4_TrakAtom::AP4_TrakAtom
+---------------------------------------------------------------------*/
AP4_TrakAtom::AP4_TrakAtom(AP4_UI32         size,
                           AP4_ByteStream&  stream,
                           AP4_AtomFactory& atom_factory) :
    AP4_ContainerAtom(AP4_ATOM_TYPE_TRAK, size, false, stream, atom_factory)
{
    m_TkhdAtom = AP4_DYNAMIC_CAST(AP4_TkhdAtom, FindChild("tkhd"));
    m_MdhdAtom = AP4_DYNAMIC_CAST(AP4_MdhdAtom, FindChild("mdia/mdhd"));
}
コード例 #5
0
ファイル: Ap4OmaDcf.cpp プロジェクト: satram/Bento4
/*----------------------------------------------------------------------
|   AP4_OmaDcfAtomDecrypter::DecryptAtoms
+---------------------------------------------------------------------*/
AP4_Result
AP4_OmaDcfAtomDecrypter::DecryptAtoms(AP4_AtomParent&                  atoms,
                                      AP4_Processor::ProgressListener* /*listener*/,
                                      AP4_BlockCipherFactory*          block_cipher_factory,
                                      AP4_ProtectionKeyMap&            key_map)
{
    // default factory
    if (block_cipher_factory == NULL) {
        block_cipher_factory = &AP4_DefaultBlockCipherFactory::Instance;
    }

    unsigned int index = 1;
    for (AP4_List<AP4_Atom>::Item* item = atoms.GetChildren().FirstItem();
            item;
            item = item->GetNext()) {
        AP4_Atom* atom = item->GetData();
        if (atom->GetType() != AP4_ATOM_TYPE_ODRM) continue;

        // check that we have the key
        const AP4_DataBuffer* key = key_map.GetKey(index++);
        if (key == NULL) return AP4_ERROR_INVALID_PARAMETERS;

        // check that we have all the atoms we need
        AP4_ContainerAtom* odrm = AP4_DYNAMIC_CAST(AP4_ContainerAtom, atom);
        if (odrm == NULL) continue; // not enough info
        AP4_OdheAtom* odhe = AP4_DYNAMIC_CAST(AP4_OdheAtom, odrm->GetChild(AP4_ATOM_TYPE_ODHE));
        if (odhe == NULL) continue; // not enough info
        AP4_OddaAtom* odda = AP4_DYNAMIC_CAST(AP4_OddaAtom, odrm->GetChild(AP4_ATOM_TYPE_ODDA));;
        if (odda == NULL) continue; // not enough info
        AP4_OhdrAtom* ohdr = AP4_DYNAMIC_CAST(AP4_OhdrAtom, odhe->GetChild(AP4_ATOM_TYPE_OHDR));
        if (ohdr == NULL) continue; // not enough info

        // do nothing if the atom is not encrypted
        if (ohdr->GetEncryptionMethod() == AP4_OMA_DCF_ENCRYPTION_METHOD_NULL) {
            continue;
        }

        // create the byte stream
        AP4_ByteStream* cipher_stream = NULL;
        AP4_Result result = CreateDecryptingStream(*odrm,
                            key->GetData(),
                            key->GetDataSize(),
                            block_cipher_factory,
                            cipher_stream);
        if (AP4_SUCCEEDED(result)) {
            // replace the odda atom's payload with the decrypted stream
            odda->SetEncryptedPayload(*cipher_stream, ohdr->GetPlaintextLength());
            cipher_stream->Release();

            // the atom will now be in the clear
            ohdr->SetEncryptionMethod(AP4_OMA_DCF_ENCRYPTION_METHOD_NULL);
            ohdr->SetPaddingScheme(AP4_OMA_DCF_PADDING_SCHEME_NONE);
        }
    }

    return AP4_SUCCESS;
}
コード例 #6
0
/*----------------------------------------------------------------------
|   AP4_CompactingProcessor::TrackHandler::ProcessTrack
+---------------------------------------------------------------------*/
AP4_Result
AP4_CompactingProcessor::TrackHandler::ProcessTrack()
{
    // find the stsz atom
    AP4_ContainerAtom* stbl = AP4_DYNAMIC_CAST(AP4_ContainerAtom, m_TrakAtom->FindChild("mdia/minf/stbl"));
    if (stbl == NULL) return AP4_SUCCESS;
    AP4_StszAtom* stsz = AP4_DYNAMIC_CAST(AP4_StszAtom, stbl->GetChild(AP4_ATOM_TYPE_STSZ));
    if (stsz == NULL) return AP4_SUCCESS;
    
    // check if we can reduce the size of stsz by changing it to stz2
    AP4_UI32 max_size = 0;
    for (unsigned int i=1; i<=stsz->GetSampleCount(); i++) {
        AP4_Size sample_size;
        stsz->GetSampleSize(i, sample_size);
        if (sample_size > max_size) {
            max_size = sample_size;
        }
    }
    AP4_UI08 field_size = 0;
    if (max_size <= 0xFF) {
        field_size = 1;
    } else if (max_size <= 0xFFFF) {
        field_size = 2;
    }
    if (m_Outer.m_Verbose) printf("Track %d: ", m_TrakAtom->GetId());
    if (field_size == 0) {
        if (m_Outer.m_Verbose) {
            printf("no stz2 reduction possible\n");
        }
        return AP4_SUCCESS;
    } else {
        if (m_Outer.m_Verbose) {
            unsigned int reduction = (4-field_size)*stsz->GetSampleCount();
            printf("stz2 reduction = %d bytes\n", reduction);
            m_Outer.m_SizeReduction += reduction;
        }
    }
    
    // detach the original stsz atom so we can destroy it later
    m_StszAtom = stsz;
    stsz->Detach();
    
    // create an stz2 atom and populate its entries
    AP4_Stz2Atom* stz2 = new AP4_Stz2Atom(field_size);
    for (unsigned int i=1; i<=m_StszAtom->GetSampleCount(); i++) {
        AP4_Size sample_size;
        m_StszAtom->GetSampleSize(i, sample_size);
        stz2->AddEntry(sample_size);
    }
    stbl->AddChild(stz2);
    
    return AP4_SUCCESS;
}
コード例 #7
0
/*----------------------------------------------------------------------
|   AutoDetectAudioFragmentDuration
+---------------------------------------------------------------------*/
static unsigned int 
AutoDetectAudioFragmentDuration(AP4_ByteStream& stream, TrackCursor* cursor)
{
    // remember where we are in the stream
    AP4_Position where = 0;
    stream.Tell(where);
    AP4_LargeSize stream_size = 0;
    stream.GetSize(stream_size);
    AP4_LargeSize bytes_available = stream_size-where;
    
    AP4_UI64  fragment_count = 0;
    AP4_UI32  last_fragment_size = 0;
    AP4_Atom* atom = NULL;
    while (AP4_SUCCEEDED(AP4_DefaultAtomFactory::Instance.CreateAtomFromStream(stream, bytes_available, atom))) {
        if (atom && atom->GetType() == AP4_ATOM_TYPE_MOOF) {
            AP4_ContainerAtom* moof = AP4_DYNAMIC_CAST(AP4_ContainerAtom, atom);
            AP4_TfhdAtom* tfhd = AP4_DYNAMIC_CAST(AP4_TfhdAtom, moof->FindChild("traf/tfhd"));
            if (tfhd && tfhd->GetTrackId() == cursor->m_Track->GetId()) {
                ++fragment_count;
                AP4_TrunAtom* trun = AP4_DYNAMIC_CAST(AP4_TrunAtom, moof->FindChild("traf/trun"));
                if (trun) {
                    last_fragment_size = trun->GetEntries().ItemCount();
                }
            }
        }
        delete atom;
        atom = NULL;
    }
    
    // restore the stream to its original position
    stream.Seek(where);
    
    // decide if we can infer an fragment size
    if (fragment_count == 0 || cursor->m_Samples->GetSampleCount() == 0) {
        return 0;
    }
    // don't count the last fragment if we have more than one
    if (fragment_count > 1 && last_fragment_size) {
        --fragment_count;
    }
    if (fragment_count <= 1 || cursor->m_Samples->GetSampleCount() < last_fragment_size) {
        last_fragment_size = 0;
    }
    AP4_Sample sample;
    AP4_UI64 total_duration = 0;
    for (unsigned int i=0; i<cursor->m_Samples->GetSampleCount()-last_fragment_size; i++) {
        cursor->m_Samples->GetSample(i, sample);
        total_duration += sample.GetDuration();
    }
    return (unsigned int)AP4_ConvertTime(total_duration/fragment_count, cursor->m_Track->GetMediaTimeScale(), 1000);
}
コード例 #8
0
/*----------------------------------------------------------------------
|   AP4_FragmentSampleTable::AP4_FragmentSampleTable
+---------------------------------------------------------------------*/
AP4_FragmentSampleTable::AP4_FragmentSampleTable(AP4_ContainerAtom* traf,
        AP4_TrexAtom*      trex,
        AP4_Cardinal       internal_track_id,
        AP4_ByteStream*    sample_stream,
        AP4_Position       moof_offset,
        AP4_Position       mdat_payload_offset,
        AP4_UI64           dts_origin)
    :m_InternalTrackId(internal_track_id)
{
    AP4_TfhdAtom* tfhd = AP4_DYNAMIC_CAST(AP4_TfhdAtom, traf->GetChild(AP4_ATOM_TYPE_TFHD));
    if (tfhd == NULL) return;

    // count all the samples and reserve space for them
    unsigned int sample_count = 0;
    for (AP4_List<AP4_Atom>::Item* item = traf->GetChildren().FirstItem();
            item;
            item = item->GetNext()) {
        AP4_Atom* atom = item->GetData();
        if (atom->GetType() == AP4_ATOM_TYPE_TRUN) {
            AP4_TrunAtom* trun = AP4_DYNAMIC_CAST(AP4_TrunAtom, atom);
            if (trun) sample_count += trun->GetEntries().ItemCount();
        }
    }
    m_Samples.EnsureCapacity(sample_count);

    // check if we have a timecode base
    AP4_TfdtAtom* tfdt = AP4_DYNAMIC_CAST(AP4_TfdtAtom, traf->GetChild(AP4_ATOM_TYPE_TFDT));
    if (tfdt) {
        dts_origin = tfdt->GetBaseMediaDecodeTime();
    }

    // process all the trun atoms
    for (AP4_List<AP4_Atom>::Item* item = traf->GetChildren().FirstItem();
            item;
            item = item->GetNext()) {
        AP4_Atom* atom = item->GetData();
        if (atom->GetType() == AP4_ATOM_TYPE_TRUN) {
            AP4_TrunAtom* trun = AP4_DYNAMIC_CAST(AP4_TrunAtom, atom);
            if (trun) {
                AP4_Result result = AddTrun(trun,
                                            tfhd,
                                            trex,
                                            sample_stream,
                                            moof_offset,
                                            mdat_payload_offset,
                                            dts_origin);
                if (AP4_FAILED(result)) return;
            }
        }
    }
}
コード例 #9
0
AP4_Result
AP4_Processor::NormalizeTRAF(AP4_ContainerAtom *atom, AP4_UI32 start, AP4_UI32 end, AP4_UI32 &index)
{
	for (; AP4_Atom* child = atom->GetChild(AP4_ATOM_TYPE_TRAF, index);) {
		AP4_TrafAtom* traf = AP4_DYNAMIC_CAST(AP4_TrafAtom, child);
		AP4_TfhdAtom* tfhd = AP4_DYNAMIC_CAST(AP4_TfhdAtom, traf->GetChild(AP4_ATOM_TYPE_TFHD));
		while (start < end && m_TrackData[start].original_id != tfhd->GetTrackId())
			;
		tfhd->SetTrackId(m_TrackData[start].new_id);
		traf->SetInternalTrackId(start);
		++index;
	}
	return AP4_SUCCESS;
}
コード例 #10
0
ファイル: Ap4TrakAtom.cpp プロジェクト: olegloa/wkrj
/*----------------------------------------------------------------------
|   AP4_TrakAtom::AdjustChunkOffsets
+---------------------------------------------------------------------*/
AP4_Result    
AP4_TrakAtom::AdjustChunkOffsets(AP4_SI64 delta)
{
    AP4_Atom* atom;
    if ((atom = FindChild("mdia/minf/stbl/stco"))) {    
        AP4_StcoAtom* stco = AP4_DYNAMIC_CAST(AP4_StcoAtom, atom);
        return stco->AdjustChunkOffsets((int)delta);
    } else if ((atom = FindChild("mdia/minf/stbl/co64"))) {
        AP4_Co64Atom* co64 = AP4_DYNAMIC_CAST(AP4_Co64Atom, atom);
        return co64->AdjustChunkOffsets(delta);
    } else {
        return AP4_ERROR_INVALID_STATE;
    }
}
コード例 #11
0
/*----------------------------------------------------------------------
|   AP4_HintTrackReader::AP4_HintTrackReader
+---------------------------------------------------------------------*/
AP4_HintTrackReader::AP4_HintTrackReader(AP4_Track& hint_track, 
                                         AP4_Movie& movie,
                                         AP4_UI32   ssrc) :
    m_HintTrack(hint_track),
    m_MediaTrack(NULL),
    m_MediaTimeScale(0),
    m_RtpSampleData(NULL),
    m_Ssrc(ssrc),
    m_SampleIndex(0),
    m_PacketIndex(0),
    m_RtpSequenceStart(0),
    m_RtpTimeStampStart(0),
    m_RtpTimeScale(0)
{
    // get the media track
    AP4_TrakAtom* hint_trak_atom = hint_track.UseTrakAtom();
    AP4_Atom* atom = hint_trak_atom->FindChild("tref/hint");
    if (atom != NULL) {
        AP4_UI32 media_track_id = AP4_DYNAMIC_CAST(AP4_TrefTypeAtom, atom)->GetTrackIds()[0];
        m_MediaTrack = movie.GetTrack(media_track_id);

        // get the media time scale
        m_MediaTimeScale = m_MediaTrack->GetMediaTimeScale();
    }

    // initiate random generator
    srand((int)time(NULL));

    // rtp sequence start init TODO!!
    m_RtpSequenceStart = (AP4_UI16)(rand()&0xFFFF);

    // rtp timestamp start init TODO!!
    m_RtpTimeStampStart = rand();

    // rtp time scale
    atom = hint_trak_atom->FindChild("mdia/minf/stbl/rtp /tims");
    if (atom) {
        AP4_TimsAtom* tims = AP4_DYNAMIC_CAST(AP4_TimsAtom, atom);
        m_RtpTimeScale = tims->GetTimeScale();
    }

    // generate a random ssrc if = 0
    if (m_Ssrc == 0) {
        m_Ssrc = rand();
    }

    // get the first sample
    GetRtpSample(0);
}
コード例 #12
0
  virtual AP4_Result ProcessMoof(AP4_ContainerAtom* moof,
    AP4_Position       moof_offset,
    AP4_Position       mdat_payload_offset)
  {
    if (m_Protected_desc)
    {
      //Setup the decryption
      AP4_Result result;
      AP4_CencSampleInfoTable *sample_table;
      AP4_UI32 algorithm_id = 0;

      delete m_Decrypter;
      m_Decrypter = 0;

      AP4_ContainerAtom *traf = AP4_DYNAMIC_CAST(AP4_ContainerAtom, moof->GetChild(AP4_ATOM_TYPE_TRAF, 0));

      if (!m_Protected_desc || !traf)
        return AP4_ERROR_INVALID_FORMAT;

      if (AP4_FAILED(result = AP4_CencSampleInfoTable::Create(m_Protected_desc, traf, algorithm_id, *m_FragmentStream, moof_offset, sample_table)))
        return result;

      if (AP4_FAILED(result = AP4_CencSampleDecrypter::Create(sample_table, algorithm_id, 0, 0, 0, m_SingleSampleDecryptor, m_Decrypter)))
        return result;
    }
    return AP4_LinearReader::ProcessMoof(moof, moof_offset, mdat_payload_offset);
  }
コード例 #13
0
ファイル: Ap4File.cpp プロジェクト: Tphive/mpc-be
/*----------------------------------------------------------------------
|       AP4_File::AP4_File
+---------------------------------------------------------------------*/
AP4_File::AP4_File(AP4_ByteStream& stream, AP4_AtomFactory& atom_factory) :
    m_Movie(NULL)
{
    // get all atoms
    AP4_Atom* atom;
    while (AP4_SUCCEEDED(atom_factory.CreateAtomFromStream(stream, atom))) {
        switch (atom->GetType()) {
        case AP4_ATOM_TYPE_MOOV:
            m_Movie = new AP4_Movie(dynamic_cast<AP4_MoovAtom*>(atom),
                                    stream);
            break;
        case AP4_ATOM_TYPE_MOOF:
            if (m_Movie) {
                m_Movie->ProcessMoof(AP4_DYNAMIC_CAST(AP4_ContainerAtom, atom),
                                     stream);
            }
            delete atom;
            break;
        case AP4_ATOM_TYPE_FTYP:
            //m_Movie = new AP4_Movie(dynamic_cast<AP4_FtypAtom*>(atom),  stream);
            m_FileType = dynamic_cast<AP4_FtypAtom*>(atom);
        default:
            m_OtherAtoms.Add(atom);
        }
    }
}
コード例 #14
0
  virtual bool GetVideoInformation(unsigned int &width, unsigned int &height) override
  {
    if (pictureId == pictureIdPrev)
      return false;
    pictureIdPrev = pictureId;

    if (AP4_AvcSampleDescription *avc = AP4_DYNAMIC_CAST(AP4_AvcSampleDescription, sample_description))
    {
      AP4_Array<AP4_DataBuffer>& buffer = avc->GetPictureParameters();
      AP4_AvcPictureParameterSet pps;
      for (unsigned int i(0); i < buffer.ItemCount(); ++i)
      {
        if (AP4_SUCCEEDED(AP4_AvcFrameParser::ParsePPS(buffer[i].GetData(), buffer[i].GetDataSize(), pps)) && pps.pic_parameter_set_id == pictureId)
        {
          buffer = avc->GetSequenceParameters();
          AP4_AvcSequenceParameterSet sps;
          for (unsigned int i(0); i < buffer.ItemCount(); ++i)
          {
            if (AP4_SUCCEEDED(AP4_AvcFrameParser::ParseSPS(buffer[i].GetData(), buffer[i].GetDataSize(), sps)) && sps.seq_parameter_set_id == pps.seq_parameter_set_id)
            {
              sps.GetInfo(width, height);
              return true;
            }
          }
          break;
        }
      }
    }
    return false;
  };
コード例 #15
0
ファイル: Ap4SampleEntry.cpp プロジェクト: qmwd2006/bento4
/*----------------------------------------------------------------------
|   AP4_Mp4sSampleEntry::ToSampleDescription
+---------------------------------------------------------------------*/
AP4_SampleDescription*
AP4_Mp4sSampleEntry::ToSampleDescription()
{
    // create a sample description
    return new AP4_MpegSystemSampleDescription(
        AP4_DYNAMIC_CAST(AP4_EsdsAtom, GetChild(AP4_ATOM_TYPE_ESDS)));
}
コード例 #16
0
/*----------------------------------------------------------------------
|   AP4_Track::GetTrackLanguage
+---------------------------------------------------------------------*/
const char*
AP4_Track::GetTrackLanguage()
{
    if (AP4_MdhdAtom* mdhd = AP4_DYNAMIC_CAST(AP4_MdhdAtom, m_TrakAtom->FindChild("mdia/mdhd"))) {
        return mdhd->GetLanguage().GetChars();
    }
    return NULL;
}
コード例 #17
0
/*----------------------------------------------------------------------
|   AP4_Track::GetTrackName
+---------------------------------------------------------------------*/
const char*
AP4_Track::GetTrackName()
{
    if (AP4_HdlrAtom* hdlr = AP4_DYNAMIC_CAST(AP4_HdlrAtom, m_TrakAtom->FindChild("mdia/hdlr"))) {
        return hdlr->GetHandlerName().GetChars();
    }
    return NULL;
}
コード例 #18
0
 MPEGCodecHandler(AP4_SampleDescription *sd)
   :CodecHandler(sd)
 {
   if (AP4_MpegSampleDescription *aac = AP4_DYNAMIC_CAST(AP4_MpegSampleDescription, sample_description))
   {
     extra_data_size = aac->GetDecoderInfo().GetDataSize();
     extra_data = aac->GetDecoderInfo().GetData();
   }
 }
コード例 #19
0
ファイル: Ap4SampleEntry.cpp プロジェクト: qmwd2006/bento4
/*----------------------------------------------------------------------
|   AP4_MpegAudioSampleEntry::ToSampleDescription
+---------------------------------------------------------------------*/
AP4_SampleDescription*
AP4_MpegAudioSampleEntry::ToSampleDescription()
{
    // find the esds atom
    AP4_EsdsAtom* esds = AP4_DYNAMIC_CAST(AP4_EsdsAtom, GetChild(AP4_ATOM_TYPE_ESDS));
    if (esds == NULL) {
        // check if this is a quicktime style sample description
        if (m_QtVersion > 0) {
            esds = AP4_DYNAMIC_CAST(AP4_EsdsAtom, FindChild("wave/esds"));
        }
    }
    
    // create a sample description
    return new AP4_MpegAudioSampleDescription(GetSampleRate(),
                                              GetSampleSize(),
                                              GetChannelCount(),
                                              esds);
}
コード例 #20
0
ファイル: Ap4LinearReader.cpp プロジェクト: olegloa/wkrj
/*----------------------------------------------------------------------
|   AP4_LinearReader::AdvanceFragment
+---------------------------------------------------------------------*/
AP4_Result
AP4_LinearReader::AdvanceFragment()
{
    AP4_Result result;
     
    // go the the start of the next fragment
    result = m_FragmentStream->Seek(m_NextFragmentPosition);
    if (AP4_FAILED(result)) return result;

    // read atoms until we find a moof
    assert(m_HasFragments);
    if (!m_FragmentStream) return AP4_ERROR_INVALID_STATE;
    do {
        AP4_Atom* atom = NULL;
        result = AP4_DefaultAtomFactory::Instance.CreateAtomFromStream(*m_FragmentStream, atom);
        if (AP4_SUCCEEDED(result)) {
            if (atom->GetType() == AP4_ATOM_TYPE_MOOF) {
                AP4_ContainerAtom* moof = AP4_DYNAMIC_CAST(AP4_ContainerAtom, atom);
                if (moof) {
                    // remember where we are in the stream
                    AP4_Position position = 0;
                    m_FragmentStream->Tell(position);
        
                    // process the movie fragment
                    result = ProcessMoof(moof, position-atom->GetSize(), position+8);
                    if (AP4_FAILED(result)) return result;

                    // compute where the next fragment will be
                    AP4_UI32 size;
                    AP4_UI32 type;
                    m_FragmentStream->Tell(position);
                    result = m_FragmentStream->ReadUI32(size);
                    if (AP4_FAILED(result)) return AP4_SUCCESS; // can't read more
                    result = m_FragmentStream->ReadUI32(type);
                    if (AP4_FAILED(result)) return AP4_SUCCESS; // can't read more
                    if (size == 0) {
                        m_NextFragmentPosition = 0;
                    } else if (size == 1) {
                        AP4_UI64 size_64 = 0;
                        result = m_FragmentStream->ReadUI64(size_64);
                        if (AP4_FAILED(result)) return AP4_SUCCESS; // can't read more
                        m_NextFragmentPosition = position+size_64;
                    } else {
                        m_NextFragmentPosition = position+size;
                    }
                    return AP4_SUCCESS;
                } else {
                    delete atom;
                }
            } else {
                delete atom;
            }            
        }
    } while (AP4_SUCCEEDED(result));
        
    return AP4_ERROR_EOS;
}
コード例 #21
0
 HEVCCodecHandler(AP4_SampleDescription *sd)
   :CodecHandler(sd)
 {
   if (AP4_HevcSampleDescription *hevc = AP4_DYNAMIC_CAST(AP4_HevcSampleDescription, sample_description))
   {
     extra_data_size = hevc->GetRawBytes().GetDataSize();
     extra_data = hevc->GetRawBytes().GetData();
     naluLengthSize = hevc->GetNaluLengthSize();
   }
 }
コード例 #22
0
 AVCCodecHandler(AP4_SampleDescription *sd)
   : CodecHandler(sd)
   , countPictureSetIds(0)
 {
   unsigned int width(0), height(0);
   if (AP4_VideoSampleDescription *video_sample_description = AP4_DYNAMIC_CAST(AP4_VideoSampleDescription, sample_description))
   {
     width = video_sample_description->GetWidth();
     height = video_sample_description->GetHeight();
   }
   if (AP4_AvcSampleDescription *avc = AP4_DYNAMIC_CAST(AP4_AvcSampleDescription, sample_description))
   {
     extra_data_size = avc->GetRawBytes().GetDataSize();
     extra_data = avc->GetRawBytes().GetData();
     countPictureSetIds = avc->GetPictureParameters().ItemCount();
     if (countPictureSetIds > 1 || !width || !height)
       naluLengthSize = avc->GetNaluLengthSize();
   }
 }
コード例 #23
0
/*----------------------------------------------------------------------
|   AP4_HintTrackReader::GetSdpText
+---------------------------------------------------------------------*/
AP4_Result
AP4_HintTrackReader::GetSdpText(AP4_String& sdp_text)
{
    AP4_Atom* sdp_atom = m_HintTrack.UseTrakAtom()->FindChild("udta/hnti/sdp ");
    if (sdp_atom == NULL) return AP4_FAILURE;

    // C cast is OK because we know the type of the atom
    sdp_text = AP4_DYNAMIC_CAST(AP4_SdpAtom, sdp_atom)->GetSdpText(); 
    return AP4_SUCCESS;
}
コード例 #24
0
 virtual bool GetAudioInformation(unsigned int &channels)
 {
   AP4_AudioSampleDescription *mpeg = AP4_DYNAMIC_CAST(AP4_AudioSampleDescription, sample_description);
   if (mpeg != nullptr && mpeg->GetChannelCount() != channels)
   {
     channels = mpeg->GetChannelCount();
     return true;
   }
   return false;
 }
コード例 #25
0
/*----------------------------------------------------------------------
|   AP4_Avc1SampleEntry::ToSampleDescription
+---------------------------------------------------------------------*/
AP4_SampleDescription*
AP4_Avc1SampleEntry::ToSampleDescription()
{
    return new AP4_AvcSampleDescription(
        m_Width,
        m_Height,
        m_Depth,
        m_CompressorName.GetChars(),
        AP4_DYNAMIC_CAST(AP4_AvccAtom, GetChild(AP4_ATOM_TYPE_AVCC)));
}
コード例 #26
0
ファイル: Ap4Track.cpp プロジェクト: 9aa5/Bento4
/*----------------------------------------------------------------------
|   AP4_Track::AP4_Track
+---------------------------------------------------------------------*/
AP4_Track::AP4_Track(AP4_TrakAtom&   atom, 
                     AP4_ByteStream& sample_stream, 
                     AP4_UI32        movie_time_scale) :
    m_TrakAtom(&atom),
    m_TrakAtomIsOwned(false),
    m_Type(TYPE_UNKNOWN),
    m_SampleTable(NULL),
    m_SampleTableIsOwned(true),
    m_MovieTimeScale(movie_time_scale)
{
    // find the handler type
    AP4_Atom* sub = atom.FindChild("mdia/hdlr");
    if (sub) {
        AP4_HdlrAtom* hdlr = AP4_DYNAMIC_CAST(AP4_HdlrAtom, sub);
        if (hdlr) {
            AP4_UI32 type = hdlr->GetHandlerType();
            if (type == AP4_HANDLER_TYPE_SOUN) {
                m_Type = TYPE_AUDIO;
            } else if (type == AP4_HANDLER_TYPE_VIDE) {
                m_Type = TYPE_VIDEO;
            } else if (type == AP4_HANDLER_TYPE_HINT) {
                m_Type = TYPE_HINT;
            } else if (type == AP4_HANDLER_TYPE_ODSM ||
                       type == AP4_HANDLER_TYPE_SDSM) {
                m_Type = TYPE_SYSTEM;
            } else if (type == AP4_HANDLER_TYPE_TEXT ||
                       type == AP4_HANDLER_TYPE_TX3G) {
                m_Type = TYPE_TEXT;
            } else if (type == AP4_HANDLER_TYPE_JPEG) {
                m_Type = TYPE_JPEG;
            } else if (type == AP4_HANDLER_TYPE_SUBT) {
                m_Type = TYPE_SUBTITLES;
            }
        }
    }

    // create a facade for the stbl atom
    AP4_ContainerAtom* stbl = AP4_DYNAMIC_CAST(AP4_ContainerAtom, atom.FindChild("mdia/minf/stbl"));
    if (stbl) {
        m_SampleTable = new AP4_AtomSampleTable(stbl, sample_stream);
    }
}
コード例 #27
0
ファイル: Ap4SampleEntry.cpp プロジェクト: qmwd2006/bento4
/*----------------------------------------------------------------------
|   AP4_MpegVideoSampleEntry::ToSampleDescription
+---------------------------------------------------------------------*/
AP4_SampleDescription*
AP4_MpegVideoSampleEntry::ToSampleDescription()
{
    // create a sample description
    return new AP4_MpegVideoSampleDescription(
        m_Width,
        m_Height,
        m_Depth,
        m_CompressorName.GetChars(),
        AP4_DYNAMIC_CAST(AP4_EsdsAtom, GetChild(AP4_ATOM_TYPE_ESDS)));
}
コード例 #28
0
/*----------------------------------------------------------------------
|   AP4_Track::GetFlags
+---------------------------------------------------------------------*/
AP4_UI32
AP4_Track::GetFlags()
{
    if (m_TrakAtom) {
        AP4_TkhdAtom* tkhd = AP4_DYNAMIC_CAST(AP4_TkhdAtom, m_TrakAtom->FindChild("tkhd"));
        if (tkhd) {
            return tkhd->GetFlags();
        }
    }
    return 0;
}
コード例 #29
0
/*----------------------------------------------------------------------
|   AP4_StsdAtom::GetSampleEntry
+---------------------------------------------------------------------*/
AP4_SampleEntry*
AP4_StsdAtom::GetSampleEntry(AP4_Ordinal index)
{
    // check index
    if (index >= m_Children.ItemCount()) return NULL;

    // return the sample entry
    AP4_Atom* entry;
    m_Children.Get(index, entry);
    return AP4_DYNAMIC_CAST(AP4_SampleEntry, entry);
}
コード例 #30
0
/*----------------------------------------------------------------------
|   AP4_Track::GetHandlerType
+---------------------------------------------------------------------*/
AP4_UI32
AP4_Track::GetHandlerType()
{
    if (m_TrakAtom) {
        AP4_HdlrAtom* hdlr = AP4_DYNAMIC_CAST(AP4_HdlrAtom, m_TrakAtom->FindChild("mdia/hdlr"));
        if (hdlr) {
            return hdlr->GetHandlerType();
        }
    }
    return 0;
}