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 26using namespace android; 27using namespace webm; 28 29namespace { 30sp<ABuffer> toABuffer(MediaBuffer *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 37namespace android { 38 39const sp<WebmFrame> WebmFrame::EOS = new WebmFrame(); 40 41WebmFrame::WebmFrame() 42 : mType(kInvalidType), 43 mKey(false), 44 mAbsTimecode(UINT64_MAX), 45 mData(new ABuffer(0)), 46 mEos(true) { 47} 48 49WebmFrame::WebmFrame(int type, bool key, uint64_t absTimecode, MediaBuffer *mbuf) 50 : mType(type), 51 mKey(key), 52 mAbsTimecode(absTimecode), 53 mData(toABuffer(mbuf)), 54 mEos(false) { 55} 56 57sp<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 65bool WebmFrame::operator<(const WebmFrame &other) const { 66 if (this->mEos) { 67 return false; 68 } 69 if (other.mEos) { 70 return true; 71 } 72 if (this->mAbsTimecode == other.mAbsTimecode) { 73 if (this->mType == kAudioType && other.mType == kVideoType) { 74 return true; 75 } 76 if (this->mType == kVideoType && other.mType == kAudioType) { 77 return false; 78 } 79 return false; 80 } 81 return this->mAbsTimecode < other.mAbsTimecode; 82} 83} /* namespace android */ 84