Home | History | Annotate | Download | only in webm
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 //#define LOG_NDEBUG 0
     18 #define LOG_TAG "WebmFrame"
     19 
     20 #include "WebmFrame.h"
     21 #include "WebmConstants.h"
     22 
     23 #include <media/stagefright/foundation/ADebug.h>
     24 #include <unistd.h>
     25 
     26 using namespace android;
     27 using namespace webm;
     28 
     29 namespace {
     30 sp<ABuffer> toABuffer(MediaBufferBase *mbuf) {
     31     sp<ABuffer> abuf = new ABuffer(mbuf->range_length());
     32     memcpy(abuf->data(), (uint8_t*) mbuf->data() + mbuf->range_offset(), mbuf->range_length());
     33     return abuf;
     34 }
     35 }
     36 
     37 namespace android {
     38 
     39 const sp<WebmFrame> WebmFrame::EOS = new WebmFrame();
     40 
     41 WebmFrame::WebmFrame()
     42     : mType(kInvalidType),
     43       mKey(false),
     44       mAbsTimecode(UINT64_MAX),
     45       mData(new ABuffer(0)),
     46       mEos(true) {
     47 }
     48 
     49 WebmFrame::WebmFrame(int type, bool key, uint64_t absTimecode, MediaBufferBase *mbuf)
     50     : mType(type),
     51       mKey(key),
     52       mAbsTimecode(absTimecode),
     53       mData(toABuffer(mbuf)),
     54       mEos(false) {
     55 }
     56 
     57 sp<WebmElement> WebmFrame::SimpleBlock(uint64_t baseTimecode) const {
     58     return new WebmSimpleBlock(
     59             mType == kVideoType ? kVideoTrackNum : kAudioTrackNum,
     60             mAbsTimecode - baseTimecode,
     61             mKey,
     62             mData);
     63 }
     64 
     65 uint64_t WebmFrame::getAbsTimecode() {
     66     return mAbsTimecode;
     67 }
     68 
     69 void WebmFrame::updateAbsTimecode(uint64_t newAbsTimecode) {
     70     mAbsTimecode = newAbsTimecode;
     71 }
     72 
     73 bool WebmFrame::operator<(const WebmFrame &other) const {
     74     if (this->mEos) {
     75         return false;
     76     }
     77     if (other.mEos) {
     78         return true;
     79     }
     80     if (this->mAbsTimecode == other.mAbsTimecode) {
     81         if (this->mType == kAudioType && other.mType == kVideoType) {
     82             return true;
     83         }
     84         if (this->mType == kVideoType && other.mType == kAudioType) {
     85             return false;
     86         }
     87         return false;
     88     }
     89     return this->mAbsTimecode < other.mAbsTimecode;
     90 }
     91 } /* namespace android */
     92