1 /* 2 * Copyright (C) 2018 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 #ifndef OGG_WRITER_H_ 18 19 #define OGG_WRITER_H_ 20 21 #include <stdio.h> 22 23 #include <media/stagefright/MediaWriter.h> 24 #include <utils/threads.h> 25 26 struct OggStreamState; 27 28 namespace android { 29 30 struct OggWriter : public MediaWriter { 31 OggWriter(int fd); 32 33 status_t initCheck() const; 34 35 virtual status_t addSource(const sp<MediaSource>& source); 36 virtual bool reachedEOS(); 37 virtual status_t start(MetaData* params = NULL); stopOggWriter38 virtual status_t stop() { return reset(); } 39 virtual status_t pause(); 40 41 protected: 42 ~OggWriter(); 43 44 private: 45 int mFd; 46 bool mHaveAllCodecSpecificData; 47 status_t mInitCheck; 48 sp<MediaSource> mSource; 49 bool mStarted = false; 50 volatile bool mPaused = false; 51 volatile bool mResumed = false; 52 volatile bool mDone; 53 volatile bool mReachedEOS; 54 pthread_t mThread; 55 int64_t mSampleRate; 56 int64_t mEstimatedSizeBytes; 57 int64_t mEstimatedDurationUs; 58 59 static void* ThreadWrapper(void*); 60 status_t threadFunc(); 61 bool exceedsFileSizeLimit(); 62 bool exceedsFileDurationLimit(); 63 status_t reset(); 64 65 int32_t mCurrentPacketId; 66 OggStreamState* mOs = nullptr; 67 68 OggWriter(const OggWriter&); 69 OggWriter& operator=(const OggWriter&); 70 71 status_t writeOggHeaderPackets(unsigned char *buf, size_t size); 72 }; 73 74 } // namespace android 75 76 #endif // OGG_WRITER_H_ 77