/* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef WEBMWRITER_H_ #define WEBMWRITER_H_ #include "WebmConstants.h" #include "WebmFrameThread.h" #include "LinkedBlockingQueue.h" #include #include #include #include #include #include using namespace webm; namespace android { class WebmWriter : public MediaWriter { public: WebmWriter(int fd); WebmWriter(const char *filename); ~WebmWriter() { reset(); } status_t addSource(const sp &source); status_t start(MetaData *param = NULL); status_t stop(); status_t pause(); bool reachedEOS(); void setStartTimeOffsetMs(int ms) { mStartTimeOffsetMs = ms; } int32_t getStartTimeOffsetMs() const { return mStartTimeOffsetMs; } private: int mFd; status_t mInitCheck; uint64_t mTimeCodeScale; int64_t mStartTimestampUs; int32_t mStartTimeOffsetMs; uint64_t mSegmentOffset; uint64_t mSegmentDataStart; uint64_t mInfoOffset; uint64_t mInfoSize; uint64_t mTracksOffset; uint64_t mCuesOffset; bool mPaused; bool mStarted; bool mIsFileSizeLimitExplicitlyRequested; bool mIsRealTimeRecording; bool mStreamableFile; uint64_t mEstimatedCuesSize; Mutex mLock; List > mCuePoints; enum { kAudioIndex = 0, kVideoIndex = 1, kMaxStreams = 2, }; struct WebmStream { int mType; const char *mName; sp (*mMakeTrack)(const sp&); sp mSource; sp mTrackEntry; sp mThread; LinkedBlockingQueue > mSink; WebmStream() : mType(kInvalidType), mName("Invalid"), mMakeTrack(NULL) { } WebmStream(int type, const char *name, sp (*makeTrack)(const sp&)) : mType(type), mName(name), mMakeTrack(makeTrack) { } WebmStream &operator=(const WebmStream &other) { mType = other.mType; mName = other.mName; mMakeTrack = other.mMakeTrack; return *this; } }; WebmStream mStreams[kMaxStreams]; sp mSinkThread; size_t numTracks(); uint64_t estimateCuesSize(int32_t bitRate); void initStream(size_t idx); void release(); status_t reset(); static sp videoTrack(const sp& md); static sp audioTrack(const sp& md); DISALLOW_EVIL_CONSTRUCTORS(WebmWriter); }; } /* namespace android */ #endif /* WEBMWRITER_H_ */