PageRenderTime 23ms CodeModel.GetById 20ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/include/media/stagefright/VideoSourceDownSampler.h

http://github.com/CyanogenMod/android_frameworks_base
C++ Header | 97 lines | 38 code | 24 blank | 35 comment | 0 complexity | edb4ad2e7d2a58741f8ed5ffc1769261 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, CC0-1.0, BitTorrent-1.0, BSD-3-Clause
 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// VideoSourceDownSampler implements the MediaSource interface,
18// downsampling frames provided from a real video source.
19
20#ifndef VIDEO_SOURCE_DOWN_SAMPLER_H_
21
22#define VIDEO_SOURCE_DOWN_SAMPLER_H_
23
24#include <media/stagefright/MediaSource.h>
25#include <utils/RefBase.h>
26
27namespace android {
28
29class IMemory;
30class MediaBuffer;
31class MetaData;
32
33class VideoSourceDownSampler : public MediaSource {
34public:
35    virtual ~VideoSourceDownSampler();
36
37    // Constructor:
38    // videoSource: The real video source which provides the original frames.
39    // width, height: The desired width, height. These should be less than or equal
40    // to those of the real video source. We then downsample the original frames to
41    // this size.
42    VideoSourceDownSampler(const sp<MediaSource> &videoSource,
43        int32_t width, int32_t height);
44
45    // MediaSource interface
46    virtual status_t start(MetaData *params = NULL);
47
48    virtual status_t stop();
49
50    virtual sp<MetaData> getFormat();
51
52    virtual status_t read(
53            MediaBuffer **buffer, const ReadOptions *options = NULL);
54
55    virtual status_t pause();
56
57private:
58    // Reference to the real video source.
59    sp<MediaSource> mRealVideoSource;
60
61    // Size of frames to be provided by this source.
62    int32_t mWidth;
63    int32_t mHeight;
64
65    // Size of frames provided by the real source.
66    int32_t mRealSourceWidth;
67    int32_t mRealSourceHeight;
68
69    // Down sampling paramters.
70    int32_t mDownSampleOffsetX;
71    int32_t mDownSampleOffsetY;
72    int32_t mDownSampleSkipX;
73    int32_t mDownSampleSkipY;
74
75    // True if we need to crop the still video image to get the video frame.
76    bool mNeedDownSampling;
77
78    // Meta data. This is a copy of the real source except for the width and
79    // height parameters.
80    sp<MetaData> mMeta;
81
82    // Computes the offset, skip parameters for downsampling the original frame
83    // to the desired size.
84    void computeDownSamplingParameters();
85
86    // Downsamples the frame in sourceBuffer to size (mWidth x mHeight). A new
87    // buffer is created which stores the downsampled image.
88    void downSampleYUVImage(const MediaBuffer &sourceBuffer, MediaBuffer **buffer) const;
89
90    // Disallow these.
91    VideoSourceDownSampler(const VideoSourceDownSampler &);
92    VideoSourceDownSampler &operator=(const VideoSourceDownSampler &);
93};
94
95}  // namespace android
96
97#endif  // VIDEO_SOURCE_DOWN_SAMPLER_H_