2011-11-28 18:09:41 +00:00
|
|
|
/*
|
2012-05-04 17:07:30 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-11-28 18:09:41 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
2012-07-27 18:21:16 +00:00
|
|
|
* WebRTC's wrapper to libyuv.
|
2011-11-28 18:09:41 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-07-27 18:21:16 +00:00
|
|
|
#ifndef WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_WEBRTC_LIBYUV_H_
|
|
|
|
|
#define WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_WEBRTC_LIBYUV_H_
|
2011-11-28 18:09:41 +00:00
|
|
|
|
2012-10-24 18:33:04 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2013-06-04 09:02:37 +00:00
|
|
|
#include "webrtc/common_types.h" // RawVideoTypes.
|
2015-03-09 17:07:31 +00:00
|
|
|
#include "webrtc/common_video/rotation.h"
|
2013-06-04 09:02:37 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
2015-04-10 12:52:13 +02:00
|
|
|
#include "webrtc/video_frame.h"
|
2011-11-28 18:09:41 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// Supported video types.
|
|
|
|
|
enum VideoType {
|
|
|
|
|
kUnknown,
|
|
|
|
|
kI420,
|
|
|
|
|
kIYUV,
|
|
|
|
|
kRGB24,
|
2011-12-28 21:21:40 +00:00
|
|
|
kABGR,
|
2011-11-28 18:09:41 +00:00
|
|
|
kARGB,
|
|
|
|
|
kARGB4444,
|
|
|
|
|
kRGB565,
|
|
|
|
|
kARGB1555,
|
|
|
|
|
kYUY2,
|
|
|
|
|
kYV12,
|
|
|
|
|
kUYVY,
|
|
|
|
|
kMJPG,
|
|
|
|
|
kNV21,
|
|
|
|
|
kNV12,
|
2011-12-28 21:21:40 +00:00
|
|
|
kBGRA,
|
2011-11-28 18:09:41 +00:00
|
|
|
};
|
|
|
|
|
|
2012-11-29 10:08:16 +00:00
|
|
|
// This is the max PSNR value our algorithms can return.
|
2012-12-13 10:15:06 +00:00
|
|
|
const double kPerfectPSNR = 48.0f;
|
2012-11-29 10:08:16 +00:00
|
|
|
|
2011-12-27 23:45:30 +00:00
|
|
|
// Conversion between the RawVideoType and the LibYuv videoType.
|
|
|
|
|
// TODO(wu): Consolidate types into one type throughout WebRtc.
|
|
|
|
|
VideoType RawVideoTypeToCommonVideoVideoType(RawVideoType type);
|
|
|
|
|
|
2011-11-28 18:09:41 +00:00
|
|
|
// Calculate the required buffer size.
|
|
|
|
|
// Input:
|
2012-09-21 15:37:06 +00:00
|
|
|
// - type :The type of the designated video frame.
|
|
|
|
|
// - width :frame width in pixels.
|
|
|
|
|
// - height :frame height in pixels.
|
|
|
|
|
// Return value: :The required size in bytes to accommodate the specified
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
// video frame.
|
|
|
|
|
size_t CalcBufferSize(VideoType type, int width, int height);
|
2011-11-28 18:09:41 +00:00
|
|
|
|
2012-10-24 18:33:04 +00:00
|
|
|
// TODO(mikhal): Add unit test for these two functions and determine location.
|
2015-05-29 17:21:40 -07:00
|
|
|
// Print VideoFrame to file
|
2012-10-24 18:33:04 +00:00
|
|
|
// Input:
|
|
|
|
|
// - frame : Reference to video frame.
|
|
|
|
|
// - file : pointer to file object. It is assumed that the file is
|
|
|
|
|
// already open for writing.
|
|
|
|
|
// Return value: 0 if OK, < 0 otherwise.
|
2015-05-29 17:21:40 -07:00
|
|
|
int PrintVideoFrame(const VideoFrame& frame, FILE* file);
|
2012-10-24 18:33:04 +00:00
|
|
|
|
2015-05-29 17:21:40 -07:00
|
|
|
// Extract buffer from VideoFrame (consecutive planes, no stride)
|
2012-10-24 18:33:04 +00:00
|
|
|
// Input:
|
|
|
|
|
// - frame : Reference to video frame.
|
|
|
|
|
// - size : pointer to the size of the allocated buffer. If size is
|
|
|
|
|
// insufficient, an error will be returned.
|
|
|
|
|
// - buffer : Pointer to buffer
|
|
|
|
|
// Return value: length of buffer if OK, < 0 otherwise.
|
2015-05-29 17:21:40 -07:00
|
|
|
int ExtractBuffer(const VideoFrame& input_frame, size_t size, uint8_t* buffer);
|
2012-01-05 18:19:32 +00:00
|
|
|
// Convert To I420
|
2011-12-28 21:21:40 +00:00
|
|
|
// Input:
|
|
|
|
|
// - src_video_type : Type of input video.
|
|
|
|
|
// - src_frame : Pointer to a source frame.
|
|
|
|
|
// - crop_x/crop_y : Starting positions for cropping (0 for no crop).
|
2012-09-24 21:09:54 +00:00
|
|
|
// - src_width : src width in pixels.
|
|
|
|
|
// - src_height : src height in pixels.
|
2011-12-28 21:21:40 +00:00
|
|
|
// - sample_size : Required only for the parsing of MJPG (set to 0 else).
|
|
|
|
|
// - rotate : Rotation mode of output image.
|
|
|
|
|
// Output:
|
2012-09-24 21:09:54 +00:00
|
|
|
// - dst_frame : Reference to a destination frame.
|
2011-12-28 21:21:40 +00:00
|
|
|
// Return value: 0 if OK, < 0 otherwise.
|
|
|
|
|
|
|
|
|
|
int ConvertToI420(VideoType src_video_type,
|
|
|
|
|
const uint8_t* src_frame,
|
2015-03-09 17:07:31 +00:00
|
|
|
int crop_x,
|
|
|
|
|
int crop_y,
|
|
|
|
|
int src_width,
|
|
|
|
|
int src_height,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t sample_size,
|
2015-03-09 17:07:31 +00:00
|
|
|
VideoRotation rotation,
|
2015-05-29 17:21:40 -07:00
|
|
|
VideoFrame* dst_frame);
|
2011-12-28 21:21:40 +00:00
|
|
|
|
2012-01-05 18:19:32 +00:00
|
|
|
// Convert From I420
|
2011-12-28 21:21:40 +00:00
|
|
|
// Input:
|
2012-10-24 18:33:04 +00:00
|
|
|
// - src_frame : Reference to a source frame.
|
2011-12-28 21:21:40 +00:00
|
|
|
// - dst_video_type : Type of output video.
|
|
|
|
|
// - dst_sample_size : Required only for the parsing of MJPG.
|
|
|
|
|
// - dst_frame : Pointer to a destination frame.
|
|
|
|
|
// Return value: 0 if OK, < 0 otherwise.
|
2012-10-01 20:09:32 +00:00
|
|
|
// It is assumed that source and destination have equal height.
|
2015-05-29 17:21:40 -07:00
|
|
|
int ConvertFromI420(const VideoFrame& src_frame,
|
|
|
|
|
VideoType dst_video_type,
|
|
|
|
|
int dst_sample_size,
|
2011-12-28 21:21:40 +00:00
|
|
|
uint8_t* dst_frame);
|
2011-11-28 18:09:41 +00:00
|
|
|
|
2011-12-20 17:38:28 +00:00
|
|
|
// Compute PSNR for an I420 frame (all planes).
|
2012-11-29 10:08:16 +00:00
|
|
|
// Returns the PSNR in decibel, to a maximum of kInfinitePSNR.
|
2015-05-29 17:21:40 -07:00
|
|
|
double I420PSNR(const VideoFrame* ref_frame, const VideoFrame* test_frame);
|
2012-10-04 17:22:32 +00:00
|
|
|
// Compute SSIM for an I420 frame (all planes).
|
2015-05-29 17:21:40 -07:00
|
|
|
double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame);
|
2015-12-10 03:11:42 -08:00
|
|
|
|
|
|
|
|
} // namespace webrtc
|
2011-11-28 18:09:41 +00:00
|
|
|
|
2012-07-27 18:21:16 +00:00
|
|
|
#endif // WEBRTC_COMMON_VIDEO_LIBYUV_INCLUDE_WEBRTC_LIBYUV_H_
|