• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 MEDIA_WRITER_H_
18 
19 #define MEDIA_WRITER_H_
20 
21 #include <utils/RefBase.h>
22 #include <media/stagefright/MediaSource.h>
23 #include <media/IMediaRecorderClient.h>
24 #include <media/mediarecorder.h>
25 
26 namespace android {
27 
28 struct MediaWriter : public RefBase {
MediaWriterMediaWriter29     MediaWriter()
30         : mMaxFileSizeLimitBytes(0),
31           mMaxFileDurationLimitUs(0) {
32     }
33 
34     virtual status_t addSource(const sp<MediaSource> &source) = 0;
35     virtual bool reachedEOS() = 0;
36     virtual status_t start(MetaData *params = NULL) = 0;
37     virtual status_t stop() = 0;
38     virtual status_t pause() = 0;
setCaptureRateMediaWriter39     virtual status_t setCaptureRate(float /* captureFps */) {
40         ALOG(LOG_WARN, "MediaWriter", "setCaptureRate unsupported");
41         return ERROR_UNSUPPORTED;
42     }
43 
setMaxFileSizeMediaWriter44     virtual void setMaxFileSize(int64_t bytes) { mMaxFileSizeLimitBytes = bytes; }
setMaxFileDurationMediaWriter45     virtual void setMaxFileDuration(int64_t durationUs) { mMaxFileDurationLimitUs = durationUs; }
setListenerMediaWriter46     virtual void setListener(const sp<IMediaRecorderClient>& listener) {
47         mListener = listener;
48     }
49 
dumpMediaWriter50     virtual status_t dump(int /*fd*/, const Vector<String16>& /*args*/) {
51         return OK;
52     }
53 
setStartTimeOffsetMsMediaWriter54     virtual void setStartTimeOffsetMs(int /*ms*/) {}
getStartTimeOffsetMsMediaWriter55     virtual int32_t getStartTimeOffsetMs() const { return 0; }
setNextFdMediaWriter56     virtual status_t setNextFd(int /*fd*/) { return INVALID_OPERATION; }
updateCVODegreesMediaWriter57     virtual void updateCVODegrees(int32_t /*cvoDegrees*/) {}
updatePayloadTypeMediaWriter58     virtual void updatePayloadType(int32_t /*payloadType*/) {}
updateSocketNetworkMediaWriter59     virtual void updateSocketNetwork(int64_t /*socketNetwork*/) {}
getSequenceNumMediaWriter60     virtual uint32_t getSequenceNum() { return 0; }
getAccumulativeBytesMediaWriter61     virtual uint64_t getAccumulativeBytes() { return 0; }
62 
63 protected:
~MediaWriterMediaWriter64     virtual ~MediaWriter() {}
65     int64_t mMaxFileSizeLimitBytes;
66     int64_t mMaxFileDurationLimitUs;
67     sp<IMediaRecorderClient> mListener;
68 
notifyMediaWriter69     void notify(int msg, int ext1, int ext2) {
70         if (msg == MEDIA_RECORDER_TRACK_EVENT_INFO || msg == MEDIA_RECORDER_TRACK_EVENT_ERROR) {
71             uint32_t trackId = (ext1 >> 28) & 0xf;
72             int type = ext1 & 0xfffffff;
73             ALOG(LOG_VERBOSE, "MediaWriter", "Track event err/info msg:%d, trackId:%u, type:%d,"
74                                              "val:%d", msg, trackId, type, ext2);
75         } else {
76             ALOG(LOG_VERBOSE, "MediaWriter", "Recorder event msg:%d, ext1:%d, ext2:%d",
77                                               msg, ext1, ext2);
78         }
79         if (mListener != nullptr) {
80             mListener->notify(msg, ext1, ext2);
81         }
82     }
83 private:
84     MediaWriter(const MediaWriter &);
85     MediaWriter &operator=(const MediaWriter &);
86 };
87 
88 }  // namespace android
89 
90 #endif  // MEDIA_WRITER_H_
91