106a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra/* 206a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * Copyright (C) 2010 The Android Open Source Project 306a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * 406a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * Licensed under the Apache License, Version 2.0 (the "License"); 506a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * you may not use this file except in compliance with the License. 606a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * You may obtain a copy of the License at 706a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * 806a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * http://www.apache.org/licenses/LICENSE-2.0 906a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * 1006a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * Unless required by applicable law or agreed to in writing, software 1106a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * distributed under the License is distributed on an "AS IS" BASIS, 1206a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1306a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * See the License for the specific language governing permissions and 1406a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra * limitations under the License. 1506a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra */ 1606a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 1706a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra// VideoSourceDownSampler implements the MediaSource interface, 1806a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra// downsampling frames provided from a real video source. 1906a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 2006a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra#ifndef VIDEO_SOURCE_DOWN_SAMPLER_H_ 2106a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 2206a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra#define VIDEO_SOURCE_DOWN_SAMPLER_H_ 2306a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 2406a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra#include <media/stagefright/MediaSource.h> 2506a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra#include <utils/RefBase.h> 2606a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 2706a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatranamespace android { 2806a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 2906a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatraclass IMemory; 3006a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatraclass MediaBuffer; 3106a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatraclass MetaData; 3206a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 3306a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatraclass VideoSourceDownSampler : public MediaSource { 3406a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatrapublic: 3506a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra virtual ~VideoSourceDownSampler(); 3606a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 3706a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // Constructor: 3806a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // videoSource: The real video source which provides the original frames. 3906a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // width, height: The desired width, height. These should be less than or equal 4006a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // to those of the real video source. We then downsample the original frames to 4106a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // this size. 4206a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra VideoSourceDownSampler(const sp<MediaSource> &videoSource, 4306a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra int32_t width, int32_t height); 4406a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 4506a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // MediaSource interface 4606a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra virtual status_t start(MetaData *params = NULL); 4706a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 4806a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra virtual status_t stop(); 4906a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 5006a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra virtual sp<MetaData> getFormat(); 5106a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 5206a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra virtual status_t read( 5306a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra MediaBuffer **buffer, const ReadOptions *options = NULL); 5406a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 5506a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra virtual status_t pause(); 5606a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 5706a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatraprivate: 5806a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // Reference to the real video source. 5906a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra sp<MediaSource> mRealVideoSource; 6006a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 6106a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // Size of frames to be provided by this source. 6206a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra int32_t mWidth; 6306a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra int32_t mHeight; 6406a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 6506a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // Size of frames provided by the real source. 6606a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra int32_t mRealSourceWidth; 6706a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra int32_t mRealSourceHeight; 6806a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 6906a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // Down sampling paramters. 7006a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra int32_t mDownSampleOffsetX; 7106a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra int32_t mDownSampleOffsetY; 7206a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra int32_t mDownSampleSkipX; 7306a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra int32_t mDownSampleSkipY; 7406a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 7506a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // True if we need to crop the still video image to get the video frame. 7606a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra bool mNeedDownSampling; 7706a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 7806a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // Meta data. This is a copy of the real source except for the width and 7906a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // height parameters. 8006a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra sp<MetaData> mMeta; 8106a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 8206a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // Computes the offset, skip parameters for downsampling the original frame 8306a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // to the desired size. 8406a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra void computeDownSamplingParameters(); 8506a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 8606a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // Downsamples the frame in sourceBuffer to size (mWidth x mHeight). A new 8706a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // buffer is created which stores the downsampled image. 8806a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra void downSampleYUVImage(const MediaBuffer &sourceBuffer, MediaBuffer **buffer) const; 8906a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 9006a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra // Disallow these. 9106a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra VideoSourceDownSampler(const VideoSourceDownSampler &); 9206a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra VideoSourceDownSampler &operator=(const VideoSourceDownSampler &); 9306a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra}; 9406a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 9506a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra} // namespace android 9606a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra 9706a1d619aad17be48f6636b8dd68914da9e9ee53Nipun Kwatra#endif // VIDEO_SOURCE_DOWN_SAMPLER_H_ 98