提交 891a40fa 编写于 作者: Z Zhang Rui

ijksdl: overlay defined based on fourcc

上级 b491ba2c
......@@ -581,7 +581,7 @@ static void alloc_picture(FFPlayer *ffp)
#endif
vp->bmp = SDL_VoutCreateFFmpegYUVOverlay(vp->width, vp->height,
SDL_YV12_OVERLAY,
SDL_FCC_YV12,
ffp->vout);
if (!vp->bmp || vp->bmp->pitches[0] < vp->width) {
/* SDL allocates a buffer smaller than requested if the video
......
......@@ -25,6 +25,7 @@
#define IJKPLAYER__IJKSDL_FFINC_H
#include "libavutil/imgutils.h"
#include "libavutil/pixfmt.h"
#include "libavcodec/avcodec.h"
#include "libswscale/swscale.h"
......
......@@ -105,18 +105,16 @@ static int overlay_unlock(SDL_VoutOverlay *overlay)
return SDL_UnlockMutex(opaque->mutex);
}
SDL_VoutOverlay *SDL_VoutCreateFFmpegYUVOverlay(int width, int height, Uint32 format, SDL_Vout *display)
SDL_VoutOverlay *SDL_VoutCreateFFmpegOverlay(int width, int height, enum AVPixelFormat format, SDL_Vout *display)
{
SDLTRACE("SDL_VoutCreateFFmpegYUVOverlay(w=%d, h=%d, fmt=%.4s(0x%x, dp=%p)",
width, height, (const char*) &format, format, display);
SDLTRACE("SDL_VoutCreateFFmpegOverlay(w=%d, h=%d, fmt=%s(0x%x), dp=%p)",
width, height, av_get_pix_fmt_name(format), (int)format, display);
SDL_VoutOverlay *overlay = SDL_VoutOverlay_CreateInternal(sizeof(SDL_VoutOverlay_Opaque));
if (!overlay) {
ALOGE("SDL_VoutCreateFFmpegYUVOverlay(...)=NULL");
ALOGE("SDL_VoutCreateFFmpegOverlay(...)=NULL");
return NULL;
}
overlay->format = format;
SDL_VoutOverlay_Opaque *opaque = overlay->opaque;
overlay->format = format;
overlay->pitches = opaque->pitches;
......@@ -124,47 +122,75 @@ SDL_VoutOverlay *SDL_VoutCreateFFmpegYUVOverlay(int width, int height, Uint32 fo
overlay->w = width;
overlay->h = height;
AVFrame *frame = NULL;
AVPicture *pic = NULL;
switch (format) {
case SDL_YV12_OVERLAY:
SDLTRACE("SDL_VoutCreateFFmpegYUVOverlay(...): SDL_YV12_OVERLAY (swap UV)");
frame = alloc_avframe(opaque, AV_PIX_FMT_YUV420P, width, height);
if (frame) {
overlay_fill(overlay, frame, format, 3);
/* swap U,V */
pic = (AVPicture *) frame;
overlay->pixels[2] = pic->data[1];
overlay->pixels[1] = pic->data[2];
overlay->pitches[2] = pic->linesize[1];
overlay->pitches[1] = pic->linesize[2];
case AV_PIX_FMT_YUV420P:
opaque->frame = alloc_avframe(opaque, AV_PIX_FMT_YUV420P, width, height);
if (opaque->frame) {
overlay_fill(overlay, opaque->frame, format, 3);
}
SDLTRACE("SDL_VoutCreateFFmpegYUVOverlay(...): overlay(w=%d, h=%d, fmt=0x%x, planes=%d, pitches=%d,%d,%d)",
overlay->format = SDL_FCC_I420;
break;
default:
ALOGE("SDL_VoutCreateFFmpegOverlay(...): unknown format");
overlay->format = SDL_FCC_UNDF;
break;
}
if (overlay) {
SDLTRACE("SDL_VoutCreateFFmpegOverlay(...): overlay(w=%d, h=%d, fmt=%.4s(0x%x), planes=%d, pitches=%d,%d,%d)",
overlay->w,
overlay->h,
(char*)&overlay->format,
overlay->format,
overlay->planes,
overlay->pitches[0],
overlay->pitches[1],
overlay->pitches[2]);
if (opaque->frame) {
opaque->mutex = SDL_CreateMutex();
overlay->free_l = overlay_free_l;
overlay->lock = overlay_lock;
overlay->unlock = overlay_unlock;
} else {
overlay_free_l(overlay);
overlay = NULL;
}
}
SDLTRACE("SDL_VoutCreateFFmpegOverlay(...)=%p", overlay);
return overlay;
}
SDL_VoutOverlay *SDL_VoutCreateFFmpegYUVOverlay(int width, int height, Uint32 format, SDL_Vout *display)
{
SDLTRACE("SDL_VoutCreateFFmpegYUVOverlay(w=%d, h=%d, fmt=%.4s(0x%x, dp=%p)",
width, height, (const char*) &format, format, display);
SDL_VoutOverlay *overlay = NULL;
switch (format) {
case SDL_FCC_YV12: {
overlay = SDL_VoutCreateFFmpegOverlay(width, height, AV_PIX_FMT_YUV420P, display);
if (overlay) {
/* swap U,V */
FFSWAP(Uint8*, overlay->pixels[1], overlay->pixels[2]);
FFSWAP(Uint16, overlay->pitches[1], overlay->pitches[2]);
overlay->format = SDL_FCC_YV12;
}
break;
}
case SDL_FCC_RGBP: {
break;
}
default:
ALOGE("SDL_VoutCreateFFmpegYUVOverlay(...): unknown format");
break;
}
if (frame) {
opaque->mutex = SDL_CreateMutex();
overlay->free_l = overlay_free_l;
overlay->lock = overlay_lock;
overlay->unlock = overlay_unlock;
} else {
overlay_free_l(overlay);
overlay = NULL;
if (!overlay) {
ALOGE("SDL_VoutCreateFFmpegYUVOverlay(...)=NULL");
}
SDLTRACE("SDL_VoutCreateFFmpegYUVOverlay(...)=%p", overlay);
return overlay;
}
......@@ -26,10 +26,11 @@
#include "../ijksdl_stdinc.h"
#include "../ijksdl_vout.h"
#include "ijksdl_inc_ffmpeg.h"
SDL_VoutOverlay *SDL_VoutCreateFFmpegOverlay(int width, int height, enum AVPixelFormat format, SDL_Vout *display);
// TODO: 9 setup overlay stride to speed up memcpy
SDL_VoutOverlay *SDL_VoutCreateFFmpegYUVOverlay(int width, int height, Uint32 format, SDL_Vout *display);
SDL_VoutOverlay *SDL_VoutCreateBestFFmpegYUVOverlay(int width, int height, Uint32 format, SDL_Vout *display);
#endif
/*****************************************************************************
* ijksdl_fourcc.h
*****************************************************************************
*
* copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
*
* This file is part of ijkPlayer.
*
* ijkPlayer is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ijkPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ijkPlayer; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef IJKSDL__IJKSDL_FOURCC_H
#define IJKSDL__IJKSDL_FOURCC_H
#include "ijksdl_stdinc.h"
#include "ijksdl_endian.h"
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
# define SDL_FOURCC(a, b, c, d) \
(((uint32_t)a) | (((uint32_t)b) << 8) | (((uint32_t)c) << 16) | (((uint32_t)d) << 24))
# define SDL_TWOCC(a, b) \
((uint16_t)(a) | ((uint16_t)(b) << 8))
#else
# define SDL_FOURCC(a, b, c, d) \
(((uint32_t)d) | (((uint32_t)c) << 8) | (((uint32_t)b) << 16) | (((uint32_t)a) << 24))
# define SDL_TWOCC( a, b ) \
((uint16_t)(b) | ((uint16_t)(a) << 8))
#endif
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
# define SDL_FOURCC(a, b, c, d) \
(((uint32_t)a) | (((uint32_t)b) << 8) | (((uint32_t)c) << 16) | (((uint32_t)d) << 24))
# define SDL_TWOCC(a, b) \
((uint16_t)(a) | ((uint16_t)(b) << 8))
#else
# define SDL_FOURCC(a, b, c, d) \
(((uint32_t)d) | (((uint32_t)c) << 8) | (((uint32_t)b) << 16) | (((uint32_t)a) << 24))
# define SDL_TWOCC( a, b ) \
((uint16_t)(b) | ((uint16_t)(a) << 8))
#endif
/*-
* http://www.webartz.com/fourcc/indexyuv.htm
* http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html
* http://www.fourcc.org/yuv.php
*/
// YUV formats
#define SDL_FCC_YV12 SDL_FOURCC('Y', 'V', '1', '2') /**< bpp=12, Planar mode: Y + V + U (3 planes) */
#define SDL_FCC_IYUV SDL_FOURCC('I', 'Y', 'U', 'V') /**< bpp=12, Planar mode: Y + U + V (3 planes) */
#define SDL_FCC_I420 SDL_FOURCC('I', '4', '2', '0') /**< bpp=12, Planar mode: Y + U + V (3 planes) */
#define SDL_FCC_YUV2 SDL_FOURCC('Y', 'U', 'V', '2') /**< bpp=16, Packed mode: Y0+U0+Y1+V0 (1 plane) */
#define SDL_FCC_UYVY SDL_FOURCC('U', 'Y', 'V', 'Y') /**< bpp=16, Packed mode: U0+Y0+V0+Y1 (1 plane) */
#define SDL_FCC_YVYU SDL_FOURCC('Y', 'V', 'Y', 'U') /**< bpp=16, Packed mode: Y0+V0+Y1+U0 (1 plane) */
// RGB formats
#define SDL_FCC_RGBP SDL_FOURCC('R', 'G', 'B', 'P') /**< RGB565, AV_PIX_FMT_RGB565LE */
// undefine
#define SDL_FCC_UNDF SDL_FOURCC('U', 'N', 'D', 'F') /**< undefined */
#endif
......@@ -25,18 +25,6 @@
#define IJKSDL__IJKSDL_VIDEO_H
#include "ijksdl_stdinc.h"
/*-
* http://www.webartz.com/fourcc/indexyuv.htm
* http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html
* http://www.fourcc.org/yuv.php
*/
// bpp=12
#define SDL_YV12_OVERLAY 0x32315659 /**< Planar mode: Y + V + U (3 planes) */
#define SDL_IYUV_OVERLAY 0x56555949 /**< Planar mode: Y + U + V (3 planes) */
// bpp=16
#define SDL_YUY2_OVERLAY 0x32595559 /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
#define SDL_UYVY_OVERLAY 0x59565955 /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
#define SDL_YVYU_OVERLAY 0x55595659 /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
#include "ijksdl_fourcc.h"
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册