jiwazii:Â¥Ö÷ÄúºÃ£¬ÎÒÓиöÎÊÌ⣬ÎÒ×Ô¼ºÒ²ÓÃqt×öÁËÒ»¸ö²¥·ÅÆ÷£¬µ«ÊÇ·ÅÊÓƵµÄʱºò£¬Ç°¼¸Ö¡ÊÇÂÌÆÁµÄ£¬ºóÀ´¾ÍºÃÕý³£ÁË£¬ÕâÊÇʲôÇé¿ö¡£ÊÓƵ¸ñʽÊÇmp4µÄ¡£
(2014-05-04 14:09)
ºÙºÙ£¬ÄãµÄ½âÂëÊä³ö»º³åÇøÈ«ÊÇ0£¬ÊÓƵÊä³ö»ù±¾É϶¼ÊÇYUVÊý¾Ý£¬È«0¾ÍÊÇÂÌÉ«£¨Èç¹ûÊÇrgbµ±È»ÊǺڵģ©£¬¸Õ¿ªÊ¼¼¸Ö¡¿ÉÄܲ¢Ã»ÓнâÂë³öͼÏñ£¬È»ºóÄã¾ÍÄÃÈ«0µÄYUVÈ¥ÏÔʾÁË£¬¾ÍһƬÂÌÁË£¬Äã³õʼ»¯ÊÓƵÊä³öÄÚ´æµÄʱºò³õʼ»¯Ìî³äÏÂYUVÊý¾Ý¾ÍºÃ¡£
/**
* @brief I420ͼÏñÀà
* @details I420ͼÏñ´æ´¢£¬³õʼ»¯£¬¸üÐÂÀà
* @author xuwei
* @version 1.0.x
* @date 2011-2012
*/
#ifndef AVENGINE_COMMOM_VIDEO_FRAME_I420_H_
#define AVENGINE_COMMOM_VIDEO_FRAME_I420_H_
namespace utils {
/**
*
@class VideoFrameI420 video_frame_i420.h¡¡
* @brief I420ͼÏñÀà
*/
class VideoFrameI420 {
public:
VideoFrameI420(long width, long height)
: image_width_(width)
, image_height_(height)
, image_(NULL)
, image_size_(0)
, image_pts_(0)
, plane_y_(NULL)
, plane_u_(NULL)
, plane_v_(NULL)
, has_video_set_(false)
, new_video_stream_(true){
}
~VideoFrameI420(void) {
if (image_) {
free(image_);
}
}
/*·ÖÅäͼÏñ¿Õ¼ä*/
long AllocMemory() {
if (0 >= image_width_ || 0 >= image_height_)
{
/*kErrorCommonInvalidParameter*/
return 0x90500001;
}
/*È·±£Å¼Êý¿í¸ßµÄÄÚ´æ·ÖÅä*/
long width_adjust = image_width_ % 2 ? image_width_ + 1 : image_width_;
long height_adjust = image_height_ % 2 ? image_height_ + 1 : image_height_;
image_size_ = width_adjust * height_adjust * 3 / 2;
if (NULL != image_) {
free(image_);
}
try {
/*ΪSSE£¬MMXÖ¸Á¶à·ÖÅä32×Ö½Ú*/
image_ = reinterpret_cast<unsigned char*>(malloc(image_size_ + 32));
}
catch (...) {
image_ = NULL;
/*kErrorCommonCreateObjectException*/
return 0x90500005;
}
/*»ñÈ¡Èý¸öƽÃæµÄλÖÃ*/
long size_y = image_width_ * image_height_;
long size_uv = size_y / 4;
plane_y_ = image_;
plane_u_ = plane_y_ + size_y;
plane_v_ = plane_u_ + size_uv;
has_video_set_ = false;
/*³õʼ»¯Í¼Ïñ£¬Ê¹ÆäΪºÚÉ«»Ãæ*/
memset(plane_y_, 0, size_y);
memset(plane_u_, 128, size_y / 2);
return 0;
}
/*¸üÐÂͼÏñ*/
long Updata(const unsigned char* frame) {
if (NULL == image_)
{
/*kErrorCommonNeverInitialize*/
return 0x90500004;
}
if (frame) {
/*·Ç¿ÕΪ¸´ÖÆͼÏñ*/
memcpy(image_, frame, image_size_);
}
else {
/*Ϊ¿ÕΪÇå¿ÕͼÏñ*/
long size_y = image_width_ * image_height_;
memset(plane_y_, 0, size_y);
memset(plane_u_, 128, size_y / 2);
}
has_video_set_ = true;
return 0;
}
public:
/*ͼÏñ¿í*/
long image_width_;
/*ͼÏñ¸ß*/
long image_height_;
/*ͼÏñ´óС*/
long image_size_;
/*³ÊÏÖʱ¼ä*/
__int64 image_pts_;
/*ͼÏñÊý¾Ý*/
unsigned char* image_;
/*YƽÃæ*/
unsigned char* plane_y_;
/*UƽÃæ*/
unsigned char* plane_u_;
/*VƽÃæ*/
unsigned char* plane_v_;
/*ͼÏñ±»ÉèÖùý*/
bool has_video_set_;
/*лÃæ±êʶ*/
bool new_video_stream_;
};
}
#endif AVENGINE_COMMOM_VIDEO_FRAME_I420_H_