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
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef COMMON_VIDEO_LIBYUV_INCLUDE_WEBRTC_LIBYUV_H_
|
|
|
|
|
#define 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>
|
2016-09-17 02:39:03 -07:00
|
|
|
#include <vector>
|
2012-10-24 18:33:04 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video/video_frame.h"
|
2017-09-15 13:58:09 +02:00
|
|
|
#include "common_types.h" // NOLINT(build/include) // VideoTypes.
|
|
|
|
|
#include "typedefs.h" // NOLINT(build/include)
|
2011-11-28 18:09:41 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2017-01-10 07:44:26 -08: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
|
|
|
|
2017-04-28 07:18:05 -07:00
|
|
|
// TODO(nisse): Some downstream apps call CalcBufferSize with
|
|
|
|
|
// ::webrtc::kI420 as the first argument. Delete after they are updated.
|
|
|
|
|
const VideoType kI420 = VideoType::kI420;
|
2011-12-27 23:45:30 +00:00
|
|
|
|
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);
|
2017-06-01 10:02:26 -07:00
|
|
|
int PrintVideoFrame(const I420BufferInterface& frame, FILE* file);
|
2012-10-24 18:33:04 +00:00
|
|
|
|
2017-06-01 10:02:26 -07:00
|
|
|
// Extract buffer from VideoFrame or I420BufferInterface (consecutive
|
2016-06-13 13:06:01 +02:00
|
|
|
// 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.
|
2017-06-01 10:02:26 -07:00
|
|
|
int ExtractBuffer(const rtc::scoped_refptr<I420BufferInterface>& input_frame,
|
2016-06-13 13:06:01 +02:00
|
|
|
size_t size,
|
|
|
|
|
uint8_t* buffer);
|
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 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);
|
2017-06-01 10:02:26 -07:00
|
|
|
double I420PSNR(const I420BufferInterface& ref_buffer,
|
|
|
|
|
const I420BufferInterface& test_buffer);
|
Reland of Update test code to use I420Buffer when writing pixel data. (patchset #1 id:1 of https://codereview.webrtc.org/2343083002/ )
Reason for revert:
Will fix android build failure.
Original issue's description:
> Revert of Update test code to use I420Buffer when writing pixel data. (patchset #2 id:140001 of https://codereview.webrtc.org/2342783003/ )
>
> Reason for revert:
> I was too impatient; this made android builds fail instead. See https://build.chromium.org/p/client.webrtc/builders/Linux32%20ARM/builds/585/steps/compile/logs/stdio
>
> Original issue's description:
> > Reland of Update test code to use I420Buffer when writing pixel data. (patchset #1 id:1 of https://codereview.webrtc.org/2342123003/ )
> >
> > Reason for revert:
> > Intending to fix problem and reland.
> >
> > Original issue's description:
> > > Revert of Update test code to use I420Buffer when writing pixel data. (patchset #5 id:80001 of https://codereview.webrtc.org/2333373007/ )
> > >
> > > Reason for revert:
> > > Fails 64-bit windows builds, it turns out I missed some of the needed int/size_t casts. Example https://build.chromium.org/p/client.webrtc/waterfall?builder=Win64%20Release
> > >
> > > Hope our windows try bots get back in working shape soon.
> > >
> > > Original issue's description:
> > > > Update test code to use I420Buffer when writing pixel data.
> > > >
> > > > VideoFrameBuffer and VideoFrame will become immutable.
> > > >
> > > > BUG=webrtc:5921
> > > > R=magjed@webrtc.org, phoglund@webrtc.org
> > > >
> > > > Committed: https://crrev.com/280ad1514e44bf6717e5871526dd4632f759eb3d
> > > > Cr-Commit-Position: refs/heads/master@{#14249}
> > >
> > > TBR=phoglund@webrtc.org,palmkvist@webrtc.org,magjed@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:5921
> > >
> > > Committed: https://crrev.com/fbf14607267adf03d235273283ca452a1e564861
> > > Cr-Commit-Position: refs/heads/master@{#14251}
> >
> > TBR=phoglund@webrtc.org,palmkvist@webrtc.org,magjed@webrtc.org
> > # Skipping CQ checks because original CL landed less than 1 days ago.
> > NOPRESUBMIT=true
> > NOTREECHECKS=true
> > NOTRY=true
> > BUG=webrtc:5921
> >
> > Committed: https://crrev.com/d21534a8cfe636bbcf3d7bb151945590abc92b2a
> > Cr-Commit-Position: refs/heads/master@{#14258}
>
> TBR=phoglund@webrtc.org,palmkvist@webrtc.org,magjed@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5921
>
> Committed: https://crrev.com/3011627142bccdd73fce9fec854abb1f6b02b5c1
> Cr-Commit-Position: refs/heads/master@{#14259}
TBR=phoglund@webrtc.org,palmkvist@webrtc.org,magjed@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
BUG=webrtc:5921
Review-Url: https://codereview.webrtc.org/2347863002
Cr-Commit-Position: refs/heads/master@{#14283}
2016-09-19 00:34:46 -07:00
|
|
|
|
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);
|
2017-06-01 10:02:26 -07:00
|
|
|
double I420SSIM(const I420BufferInterface& ref_buffer,
|
|
|
|
|
const I420BufferInterface& test_buffer);
|
2015-12-10 03:11:42 -08:00
|
|
|
|
2016-10-20 03:34:29 -07:00
|
|
|
// Helper function for scaling NV12 to NV12.
|
2017-06-19 16:46:31 +02:00
|
|
|
// If the |src_width| and |src_height| matches the |dst_width| and |dst_height|,
|
|
|
|
|
// then |tmp_buffer| is not used. In other cases, the minimum size of
|
|
|
|
|
// |tmp_buffer| should be:
|
|
|
|
|
// (src_width/2) * (src_height/2) * 2 + (dst_width/2) * (dst_height/2) * 2
|
|
|
|
|
void NV12Scale(uint8_t* tmp_buffer,
|
2016-10-20 03:34:29 -07:00
|
|
|
const uint8_t* src_y, int src_stride_y,
|
|
|
|
|
const uint8_t* src_uv, int src_stride_uv,
|
|
|
|
|
int src_width, int src_height,
|
|
|
|
|
uint8_t* dst_y, int dst_stride_y,
|
|
|
|
|
uint8_t* dst_uv, int dst_stride_uv,
|
|
|
|
|
int dst_width, int dst_height);
|
|
|
|
|
|
2016-09-17 02:39:03 -07:00
|
|
|
// Helper class for directly converting and scaling NV12 to I420. The Y-plane
|
|
|
|
|
// will be scaled directly to the I420 destination, which makes this faster
|
|
|
|
|
// than separate NV12->I420 + I420->I420 scaling.
|
|
|
|
|
class NV12ToI420Scaler {
|
|
|
|
|
public:
|
2017-05-08 05:32:05 -07:00
|
|
|
NV12ToI420Scaler();
|
|
|
|
|
~NV12ToI420Scaler();
|
2016-09-17 02:39:03 -07:00
|
|
|
void NV12ToI420Scale(const uint8_t* src_y, int src_stride_y,
|
|
|
|
|
const uint8_t* src_uv, int src_stride_uv,
|
|
|
|
|
int src_width, int src_height,
|
|
|
|
|
uint8_t* dst_y, int dst_stride_y,
|
|
|
|
|
uint8_t* dst_u, int dst_stride_u,
|
|
|
|
|
uint8_t* dst_v, int dst_stride_v,
|
|
|
|
|
int dst_width, int dst_height);
|
|
|
|
|
private:
|
|
|
|
|
std::vector<uint8_t> tmp_uv_planes_;
|
|
|
|
|
};
|
|
|
|
|
|
2017-11-15 14:35:56 +05:30
|
|
|
// Convert VideoType to libyuv FourCC type
|
|
|
|
|
int ConvertVideoType(VideoType video_type);
|
|
|
|
|
|
2015-12-10 03:11:42 -08:00
|
|
|
} // namespace webrtc
|
2011-11-28 18:09:41 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // COMMON_VIDEO_LIBYUV_INCLUDE_WEBRTC_LIBYUV_H_
|