/*! * \copy * Copyright (c) 2009-2014, Cisco Systems * Copyright (c) 2014, Mozilla * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * *************************************************************************************
*/
void SendFrame(GMPVideoi420Frame* inputImage, GMPVideoFrameType frame_type, int nal_type) { // Encode this in a frame that looks a little bit like H.264. // Send SPS/PPS/IDR to avoid confusing people // Copy the data. This really should convert this to network byte order.
EncodedFrame eframe;
// These values were chosen to force a SPS id of 0
eframe.sps_nalu = {sizeof(EncodedFrame::SPSNalu) - sizeof(uint32_t),
{0x67, 0x42, 0xc0, 0xd, 0x8c, 0x8d, 0x40, 0xa0, 0xf9,
0x0, 0xf0, 0x88, 0x46, 0xa0}};
// These values were chosen to force a PPS id of 0
eframe.pps_nalu = {sizeof(EncodedFrame::PPSNalu) - sizeof(uint32_t),
{0x68, 0xce, 0x3c, 0x80}};
eframe.idr_nalu.size_ = sizeof(EncodedFrame::IDRNalu) - sizeof(uint32_t); // We force IFrame here - if we send PFrames, the webrtc.org code gets // tripped up attempting to find non-existent previous IFrames.
eframe.idr_nalu.h264_compat_ =
nal_type; // 5 = IFrame/IDR slice, 1=PFrame/slice
eframe.idr_nalu.magic_ = ENCODED_FRAME_MAGIC;
eframe.idr_nalu.width_ = inputImage->Width();
eframe.idr_nalu.height_ = inputImage->Height();
eframe.idr_nalu.y_ = AveragePlane(inputImage->Buffer(kGMPYPlane),
inputImage->AllocatedSize(kGMPYPlane));
eframe.idr_nalu.u_ = AveragePlane(inputImage->Buffer(kGMPUPlane),
inputImage->AllocatedSize(kGMPUPlane));
eframe.idr_nalu.v_ = AveragePlane(inputImage->Buffer(kGMPVPlane),
inputImage->AllocatedSize(kGMPVPlane));
// Now return the encoded data back to the parent.
GMPVideoFrame* ftmp;
GMPErr err = host_->CreateFrame(kGMPEncodedVideoFrame, &ftmp); if (err != GMPNoErr) {
GMPLOG(GL_ERROR, "Error creating encoded frame"); return;
}
GMPVideoEncodedFrame* f = static_cast<GMPVideoEncodedFrame*>(ftmp);
if (eframe->idr_nalu.magic_ != ENCODED_FRAME_MAGIC) {
GMPLOG(GL_ERROR, "Couldn't decode frame. Magic=" << eframe->idr_nalu.magic_); return;
} if (eframe->idr_nalu.h264_compat_ != 5 &&
eframe->idr_nalu.h264_compat_ != 1) { // only return video for iframes or pframes
GMPLOG(GL_DEBUG, "Not a video frame: NAL type "
<< (int)eframe->idr_nalu.h264_compat_); return;
}
int width = eframe->idr_nalu.width_; int height = eframe->idr_nalu.height_; int ystride = eframe->idr_nalu.width_; // Round up so the data fits, or CreateEmptyFrame will fail on odd width and // height. int uvstride = (ystride + (ystride % 2)) / 2;
GMPLOG(GL_DEBUG, "Video frame ready for display "
<< width << "x" << height
<< " timestamp=" << inputFrame->TimeStamp());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.