/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

  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. // VideoSourceDownSampler implements the MediaSource interface,
  17. // downsampling frames provided from a real video source.
  18. #ifndef VIDEO_SOURCE_DOWN_SAMPLER_H_
  19. #define VIDEO_SOURCE_DOWN_SAMPLER_H_
  20. #include <media/stagefright/MediaSource.h>
  21. #include <utils/RefBase.h>
  22. namespace android {
  23. class IMemory;
  24. class MediaBuffer;
  25. class MetaData;
  26. class VideoSourceDownSampler : public MediaSource {
  27. public:
  28. virtual ~VideoSourceDownSampler();
  29. // Constructor:
  30. // videoSource: The real video source which provides the original frames.
  31. // width, height: The desired width, height. These should be less than or equal
  32. // to those of the real video source. We then downsample the original frames to
  33. // this size.
  34. VideoSourceDownSampler(const sp<MediaSource> &videoSource,
  35. int32_t width, int32_t height);
  36. // MediaSource interface
  37. virtual status_t start(MetaData *params = NULL);
  38. virtual status_t stop();
  39. virtual sp<MetaData> getFormat();
  40. virtual status_t read(
  41. MediaBuffer **buffer, const ReadOptions *options = NULL);
  42. virtual status_t pause();
  43. private:
  44. // Reference to the real video source.
  45. sp<MediaSource> mRealVideoSource;
  46. // Size of frames to be provided by this source.
  47. int32_t mWidth;
  48. int32_t mHeight;
  49. // Size of frames provided by the real source.
  50. int32_t mRealSourceWidth;
  51. int32_t mRealSourceHeight;
  52. // Down sampling paramters.
  53. int32_t mDownSampleOffsetX;
  54. int32_t mDownSampleOffsetY;
  55. int32_t mDownSampleSkipX;
  56. int32_t mDownSampleSkipY;
  57. // True if we need to crop the still video image to get the video frame.
  58. bool mNeedDownSampling;
  59. // Meta data. This is a copy of the real source except for the width and
  60. // height parameters.
  61. sp<MetaData> mMeta;
  62. // Computes the offset, skip parameters for downsampling the original frame
  63. // to the desired size.
  64. void computeDownSamplingParameters();
  65. // Downsamples the frame in sourceBuffer to size (mWidth x mHeight). A new
  66. // buffer is created which stores the downsampled image.
  67. void downSampleYUVImage(const MediaBuffer &sourceBuffer, MediaBuffer **buffer) const;
  68. // Disallow these.
  69. VideoSourceDownSampler(const VideoSourceDownSampler &);
  70. VideoSourceDownSampler &operator=(const VideoSourceDownSampler &);
  71. };
  72. } // namespace android
  73. #endif // VIDEO_SOURCE_DOWN_SAMPLER_H_