/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "VideoEditorVideoDecoder.h"
#include "VideoEditor3gpReader.h"
#include <utils/Log.h>
#include "VideoBrowserInternal.h"
#include "LVOSA_FileReader_optim.h"
//#define M4OSA_TRACE_LEVEL 1
#if (M4OSA_TRACE_LEVEL >= 1)
#undef M4OSA_TRACE1_0
#undef M4OSA_TRACE1_1
#undef M4OSA_TRACE1_2
#undef M4OSA_TRACE1_3
#define M4OSA_TRACE1_0(a) __android_log_print(ANDROID_LOG_INFO, "Thumbnail", a);
#define M4OSA_TRACE1_1(a,b) __android_log_print(ANDROID_LOG_INFO, "Thumbnail", a,b);
#define M4OSA_TRACE1_2(a,b,c) __android_log_print(ANDROID_LOG_INFO, "Thumbnail", a,b,c);
#define M4OSA_TRACE1_3(a,b,c,d) __android_log_print(ANDROID_LOG_INFO, "Thumbnail", a,b,c,d);
#endif
/******************************************************************************
* M4OSA_ERR videoBrowserSetWindow(
* M4OSA_Context pContext, M4OSA_UInt32 x,
* M4OSA_UInt32 y, M4OSA_UInt32 dx, M4OSA_UInt32 dy);
* @brief This function sets the size and the position of the display.
* @param pContext (IN) : Video Browser context
* @param pPixelArray (IN) : Array to hold the video frame.
* @param x (IN) : Horizontal position of the top left
* corner
* @param y (IN) : Vertical position of the top left corner
* @param dx (IN) : Width of the display window
* @param dy (IN) : Height of the video window
* @return M4NO_ERROR / M4ERR_PARAMETER / M4ERR_STATE / M4ERR_ALLOC
******************************************************************************/
M4OSA_ERR videoBrowserSetWindow(
M4OSA_Context pContext,
M4OSA_Int32 *pPixelArray,
M4OSA_UInt32 x, M4OSA_UInt32 y,
M4OSA_UInt32 dx, M4OSA_UInt32 dy)
{
VideoBrowserContext* pC = (VideoBrowserContext*)pContext;
M4OSA_ERR err = M4NO_ERROR;
M4OSA_TRACE2_5("videoBrowserSetWindow: entering with 0x%x %d %d %d %d ",
pContext, x, y, dx, dy);
/*--- Sanity checks ---*/
CHECK_PTR(videoBrowserSetWindow, pContext, err, M4ERR_PARAMETER);
CHECK_PTR(videoBrowserSetWindow, pPixelArray, err, M4ERR_PARAMETER);
CHECK_STATE(videoBrowserSetWindow, VideoBrowser_kVBOpened, pC);
pC->m_outputPlane[0].u_topleft = 0;
pC->m_outputPlane[0].u_height = dy;
pC->m_outputPlane[0].u_width = dx;
pC->m_x = x;
pC->m_y = y;
if (pC->m_frameColorType == VideoBrowser_kGB565) {
pC->m_outputPlane[0].u_stride = pC->m_outputPlane[0].u_width << 1;
pC->m_outputPlane[0].pac_data = (M4OSA_UInt8*)M4OSA_32bitAlignedMalloc(
pC->m_outputPlane[0].u_stride * pC->m_outputPlane[0].u_height,
VIDEOBROWSER, (M4OSA_Char *)"output plane");
CHECK_PTR(videoBrowserSetWindow,
pC->m_outputPlane[0].pac_data, err, M4ERR_ALLOC);
}
else if (pC->m_frameColorType == VideoBrowser_kYUV420) {
pC->m_outputPlane[0].u_stride = pC->m_outputPlane[0].u_width;
pC->m_outputPlane[1].u_height = pC->m_outputPlane[0].u_height >> 1;
pC->m_outputPlane[1].u_width = pC->m_outputPlane[0].u_width >> 1;
pC->m_outputPlane[1].u_topleft = 0;
pC->m_outputPlane[1].u_stride = pC->m_outputPlane[1].u_width;
pC->m_outputPlane[2].u_height = pC->m_outputPlane[0].u_height >> 1;
pC->m_outputPlane[2].u_width = pC->m_outputPlane[0].u_width >> 1;
pC->m_outputPlane[2].u_topleft = 0;
pC->m_outputPlane[2].u_stride = pC->m_outputPlane[2].u_width;
pC->m_outputPlane[0].pac_data = (M4OSA_UInt8*)pPixelArray;
CHECK_PTR(videoBrowserSetWindow,
pC->m_outputPlane[0].pac_data, err, M4ERR_ALLOC);
pC->m_outputPlane[1].pac_data =
pC->m_outputPlane[0].pac_data +
(pC->m_outputPlane[0].u_stride * pC->m_outputPlane[0].u_height);
pC->m_outputPlane[2].pac_data =
pC->m_outputPlane[1].pac_data +
(pC->m_outputPlane[1].u_stride * pC->m_outputPlane[1].u_height);
}
M4OSA_TRACE2_0("videoBrowserSetWindow returned NO ERROR");
return M4NO_ERROR;
videoBrowserSetWindow_cleanUp:
M4OSA_TRACE2_1("videoBrowserSetWindow returned 0x%x", err);
return err;
}
/******************************************************************************
* @brief This function allocates the resources needed for browsing a video file
* @param ppContext (OUT): Pointer on a context filled by this function.
* @param pURL (IN) : Path of File to browse
* @param DrawMode (IN) : Indicate which method is used to draw (Direct draw etc...)
* @param pfCallback (IN) : Callback function to be called when a frame must be displayed
* @param pCallbackData (IN) : User defined data that will be passed as parameter of the callback
* @param clrType (IN) : Required color type.
* @return M4NO_ERROR / M4ERR_PARAMETER / M4ERR_STATE / M4ERR_ALLOC
******************************************************************************/
M4OSA_ERR videoBrowserCreate(
M4OSA_Context* ppContext,
M4OSA_Char* pURL,
M4OSA_UInt32 DrawMode,
M4OSA_FileReadPointer* ptrF,
videoBrowser_Callback pfCallback,
M4OSA_Void* pCallbackData,
VideoBrowser_VideoColorType clrType)
{
VideoBrowserContext* pContext = M4OSA_NULL;
M4READER_MediaFamily mediaFamily = M4READER_kMediaFamilyUnknown;
M4_StreamHandler* pStreamHandler = M4OSA_NULL;
M4_VideoStreamHandler* pVideoStreamHandler = M4OSA_NULL;
M4DECODER_VideoType decoderType;
M4DECODER_OutputFilter FilterOption;
M4OSA_Bool deb = M4OSA_TRUE;
M4OSA_ERR err = M4NO_ERROR;
M4OSA_TRACE1_2(
"videoBrowserCreate: entering with 0x%x 0x%x", ppContext, pURL);
/*--- Sanity checks ---*/
CHECK_PTR(videoBrowserCreate, ppContext, err, M4ERR_PARAMETER);
*ppContext = M4OSA_NULL ;
CHECK_PTR(videoBrowserCreate, pURL, err, M4ERR_PARAMETER);
/*--- Create context ---*/
pContext = (VideoBrowserContext*)M4OSA_32bitAlignedMalloc(
sizeof(VideoBrowserContext),
VIDEOBROWSER, (M4OSA_Char*)"Video browser context");
CHECK_PTR(videoBrowserCreate, pContext,err, M4ERR_ALLOC);
memset((void *)pContext, 0,sizeof(VideoBrowserContext));
/*--- Initialize the context parameters ---*/
pContext->m_state = VideoBrowser_kVBCreating ;
pContext->m_frameColorType = clrType;
/*--- Copy the file reader functions ---*/
memcpy((void *)&pContext->m_fileReadPtr,
(void *)ptrF,
sizeof(M4OSA_FileReadPointer)) ;
/* PR#SP00013 DGR bug 13 : first frame is not visible */
pContext->m_drawmode = DrawMode;
/* Retrieve the 3gp reader interface */
VideoEditor3gpReader_getInterface(&pContext->m_mediaType,
&pContext->m_3gpReader, &pContext->m_3gpData);
CHECK_PTR(videoBrowserCreate, pContext->m_3gpReader, err, M4ERR_ALLOC);
CHECK_PTR(videoBrowserCreate, pContext->m_3gpData, err, M4ERR_ALLOC);
/*--- Create the file reader ---*/
err = pContext->m_3gpReader->m_pFctCreate(&pContext->m_pReaderCtx);
CHECK_ERR(videoBrowserCreate, err);
CHECK_PTR(videoBrowserCreate, pContext->m_pReaderCtx, err, M4ERR_ALLOC);
pContext->m_3gpData->m_readerContext = pContext->m_pReaderCtx;
/*--- Set the OSAL file reader functions ---*/
err = pContext->m_3gpRead