Chinaunix首页 | 论坛 | 博客
  • 博客访问: 127413
  • 博文数量: 33
  • 博客积分: 948
  • 博客等级: 准尉
  • 技术积分: 380
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-19 20:47
文章分类

全部博文(33)

文章存档

2012年(2)

2011年(30)

2010年(1)

分类: LINUX

2011-01-06 19:18:25

注:网上搜索的文章

Can JPEG and MPEG4 run on DM355 simultaneity

Liu Yebo
Wed May 13 21:20:51 CDT 2009

  • Previous message:
  • Next message:
  • Messages sorted by:

Hi, 
    I have made jpeg code in demos, and It seams that JPEG and MPEG4 encoder on our board works fine at the same time.
Following is my JPEG code , you can add them into encode demos.
/* jpeg.h*/

#include 
#include 
#include 

#include 
#include 
#include 
#include "encode.h"

#ifndef __JPEG_H__
#define __JPEG_H__



int jpegEncodeAlgCreate(Engine_Handle hEngine, IMGENC1_Handle *hEncodePtr, 
                        int width, int height, int num, XDAS_Int32 *imageBufSize);


void jpegencode(IMGENC1_Handle enc, unsigned char *inBuf, unsigned int inBufSize,
                unsigned char *encodedBuf, unsigned int * encodedBufSize);

typedef struct ImageEnv {
    Rendezvous_Handle hRendezvousInit;
    Rendezvous_Handle hRendezvousCleanup;
    Pause_Handle      hPause;
    FifoUtil_Obj      inFifo;
    FifoUtil_Obj      outFifo;
    int               imageWidth;
    int               imageHeight;
    int               chcnt;
} ImageEnv;

void * imageThrFxn(void *arg);



#endif /* __JPEG_H__ */

/*jpeg.c*/



/* Standard Linux headers */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

/* Codec Engine headers */
#include 
#include 
#include 
#include "encode.h"
#include "jpeg.h"

#include "capture.h"

#include "recorder.h"

static char *jpegenc_name[MAXCHNUM] = {"jpegenc", "jpegenc:1", "jpegenc:2", "jpegenc:3"};

int jpegEncodeAlgCreate(Engine_Handle hEngine, IMGENC1_Handle *hEncodePtr, 
                        int width, int height, int num, XDAS_Int32 *imageBufSize)
{
    IMGENC1_Params image_encParams;
    IMGENC1_DynamicParams image_dynParams;
    IMGENC1_Status image_imgStatus;
    IMGENC1_Handle hEncode;

#define SCANS 4
#define QVALUE 73

    image_encParams.size = sizeof(IMGENC1_Params);
    image_encParams.maxWidth = width;
    image_encParams.maxHeight = height;
    image_encParams.maxScans = SCANS;
    image_encParams.dataEndianness = XDM_DEFAULT;
    image_encParams.forceChromaFormat = XDM_YUV_422ILE;

    hEncode = IMGENC1_create(hEngine, jpegenc_name[num], &image_encParams);
    if (NULL == hEncode)
    {
        fprintf(stderr, "error: can't open codec jpegenc\n");
        seterrdev(ERR_IMGENCCREAT);
        return FAILURE;
    }

    /* set the parameters for encoding */
    image_dynParams.size = sizeof(IMGENC1_DynamicParams);
    image_dynParams.numAU = XDM_DEFAULT;
    image_dynParams.inputChromaFormat = XDM_YUV_422ILE;
    image_dynParams.inputWidth = width;
    image_dynParams.inputHeight = height;
    image_dynParams.captureWidth = 0;
    image_dynParams.generateHeader = XDM_ENCODE_AU;
    image_dynParams.qValue = QVALUE;
    image_imgStatus.size = sizeof(image_imgStatus);
    if (IMGENC1_control(hEncode, XDM_SETPARAMS, &image_dynParams, &image_imgStatus) ==
        XDM_EFAIL) {
        fprintf(stderr, "error: could not set PARAMS: 0x%x\n", XDM_SETPARAMS);
        seterrdev(ERR_IMGENCCREAT);
        return FAILURE;
    }
 
    /* ask the codec for buffer sizes - these are typically conservative */
    if (IMGENC1_control(hEncode, XDM_GETBUFINFO, &image_dynParams, &image_imgStatus) ==
        XDM_EFAIL) {
        fprintf(stderr, "error: could not get BUFINFO: 0x%x\n", XDM_GETBUFINFO);
        seterrdev(ERR_IMGENCCREAT);
        return FAILURE;
    }

    *imageBufSize = image_imgStatus.bufInfo.minOutBufSize[0];
    *hEncodePtr = hEncode;

    return SUCCESS;
}


void jpegencode(IMGENC1_Handle enc, unsigned char *inBuf, unsigned int inBufSize,
                        unsigned char *encodedBuf, unsigned int *encodedBufSize)
{
    Int32                       status;
    IMGENC1_InArgs              encInArgs;
    IMGENC1_OutArgs             encOutArgs;
    XDM1_BufDesc                inBufDesc;
    XDM1_BufDesc                encodedBufDesc;
    //XDAS_Int32                  numRead;
 
    /* initialize buffer descriptors that hold input and output buffers */
    inBufDesc.numBufs = 1;
    inBufDesc.descs[0].bufSize = inBufSize;
    inBufDesc.descs[0].buf = inBuf;
 
    encodedBufDesc.numBufs = 1;
    encodedBufDesc.descs[0].bufSize = *encodedBufSize;
    encodedBufDesc.descs[0].buf = encodedBuf;
 
    /* the size field of Args and Params structs must be initialized */
    encInArgs.size    = sizeof(encInArgs);
    encOutArgs.size   = sizeof(encOutArgs);
    /* perform the image (JPEG) encoding */
    status = IMGENC1_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs,
                             &encOutArgs);
 
    if (status == IMGENC1_EOK) {
        *encodedBufSize = encOutArgs.bytesGenerated;
    }
    else {
        printf( "Encoder frame processing FAILED, status = 0x%lx, "
                "extendedError = 0x%lx\n", status,
                encOutArgs.extendedError);
        seterrdev(ERR_IMGENCPROC);
    }
}


void * imageThrFxn(void *arg)
{
    Engine_Handle        hEngine_en        = NULL;
    ImageEnv            *envp              = (ImageEnv *) arg;
    void                *status            = THREAD_SUCCESS;
    int                  imgWidth = envp->imageWidth/(envp->chcnt>1?2:1);
    int                  imgHeight = envp->imageHeight/(envp->chcnt>1?2:1);
    int                  ch;
    CaptureBufferElement ce;

    /* Reset, load, and starot DSP Engine */
    hEngine_en = Engine_open("image", NULL, NULL);

    if (hEngine_en == NULL) {
        ERR("Failed to open encode engine %s\n", "image");
        seterrdev(ERR_ENGINEOPNE);
        cleanup(THREAD_FAILURE);
    }
    DBG("Encode Engine opened in jpeg thread\n");

// here for mjpeg
    IMGENC1_Handle image_enc = NULL;
    XDAS_Int8 *image_encodedBuf[MAXCHNUM] = {NULL};
    XDAS_Int32 image_encodedBufSize = 0;
    XDAS_Int32 image_BufSize[MAXCHNUM];

    if(FAILURE == jpegEncodeAlgCreate(hEngine_en, &image_enc, imgWidth, imgHeight, 0, &image_encodedBufSize))
    {
        cleanup(THREAD_FAILURE);
    }
    printf("image_encodedBufSize: %lu\n", image_encodedBufSize);

    image_encodedBuf[0] = (XDAS_Int8 *)Memory_contigAlloc(image_encodedBufSize*(envp->chcnt>1?4:1), Memory_DEFAULTALIGNMENT);

    if (image_encodedBuf[0] == NULL) {
        fprintf(stderr, "image_encodedBuf[0] alloc failed!\n");
        seterrdev(ERR_SYSTEM);
        cleanup(THREAD_FAILURE);
    }

    for(ch=1; chchcnt)
            image_encodedBuf[ch] = image_encodedBuf[0] + ch*image_encodedBufSize;
        else
            image_encodedBuf[ch] = NULL;
    }

    DBG("Image encoder created.\n");

    /* Signal that initialization is done and wait for other threads */
    Rendezvous_meet(envp->hRendezvousInit);

    DBG("Entering jpeg main loop.\n");
    while (!gblGetQuit()) {
        /* Get a buffer from the capture thread */
        if (FifoUtil_get(&envp->inFifo, &ce) == FIFOUTIL_FAILURE) {
            ERR("Failed to put buffer in output fifo\n");
            seterrdev(ERR_SYSTEM);
            breakLoop(THREAD_FAILURE);
        }

        /* Is the capture thread flushing the pipe? */
        if (ce.id == CAPTURE_FLUSH) {
            ERR("Receive Flush and Break fifo\n");
            breakLoop(THREAD_SUCCESS);
        }

        ms_time_t nTime = ce.nTime; //it's time get yuv data time;


        /* Encode the captured video frame */
        char *virtBuf = ce.virtBuf;
        //int   bufSize = ce.bufSize/(envp->chcnt>1?4:1);
        int   bufSize = imgWidth*imgHeight*SCREEN_BPP/8;

        for(ch=0; chchcnt; ch++)
        {
            virtBuf = ce.virtBuf + bufSize*ch;

//here for jpegenc
            image_BufSize[ch] = image_encodedBufSize;
            jpegencode(image_enc, virtBuf, bufSize, image_encodedBuf[ch], (unsigned int *)&image_BufSize[ch]);
            //printf(".............. jpeg size %lu\n", image_BufSize[ch]);

        }

        writeJpegData(image_encodedBuf, image_BufSize, nTime);

#if 0
        /* Send the buffer back to the capture thread */
        if (FifoUtil_put(&envp->outFifo, &ce) == FIFOUTIL_FAILURE) {
            ERR("Failed to put buffer in output fifo\n");
            breakLoop(THREAD_FAILURE);
        }
#endif
    }
    DBG("Exitted jpeg main loop.\n");


cleanup:

    /* Make sure the other threads aren't waiting for init to complete */
    Rendezvous_force(envp->hRendezvousInit);

    /* Make sure the other threads aren't stuck pausing */
    Pause_off(envp->hPause);

#if 0
    /* Make sure the capture thread isn't stuck in FifoUtil_get() */
    FifoUtil_put(&envp->outFifo, &cFlush);
#endif

    /* Meet up with other threads before cleaning up */
    Rendezvous_meet(envp->hRendezvousCleanup);

    if (image_enc) {
        IMGENC1_delete(image_enc);
    }

    if (image_encodedBuf[0]) {
        Memory_contigFree(image_encodedBuf[0], image_encodedBufSize*(envp->chcnt>1?4:1));
    }

    if (hEngine_en) {
        Engine_close(hEngine_en);
    }

    return status;
}


----- Original Message ----- 
From: "Vladimir Pantelic" <>
To: <>
Cc: "davinci-linux-open-source" <>
Sent: Thursday, May 14, 2009 12:20 AM
Subject: Re: Can JPEG and MPEG4 run on DM355 simultaneity


> Steve Chen wrote:
>> On Wed, 2009-05-13 at 23:14 +0800, Jammy Dane wrote:
>>>  Hi all,
>>>
>>>  I want to run JPEG and MPEG4 encode on DM355 board, and I wrote a
>>>  demo referencing the code in ../DVSDK_1_00_30_xx/demo/encode/* and the
>>>  code in ../DVSDK_1_00_30_xx/examples/jpegenc/*. After I run the demo,
>>>  it said on the terminal:
>>>  /*********************************************************/
>>>  :/opt/dvsdk# ./encode_test_jpeg -v 1.mpeg4 -r 640x576 -b 384000
>>>  Encode demo started.
>>>   gpio control udp socket create ok!
>>>  the /dev/modem is opened
>>>  allocate modem buffer
>>>  fd = 17
>>>  Capturing 720x576 video (cropped to 640x576)
>>>  ERROR: can't open engine image
>>>  CMEMK Error: GETPHYS: Failed to convert virtual 0x4001cbe0 to physical.
>>>  CMEM Error: getPhys: Failed to get physical address of 0x4001cbe0
>>
>> Don't know much about applications, but 0x400xxxxx seems more like a
>> physical rather than virtual address to me.  Just a thought...
> 
> no, 0x4001cbe0 is a virtual address
> 
> I doubt you can run JPEG and MPEG4 at the same time, I think they share the HW.
> 
> but, in any case, run with CE_DEBGU=2
> 
> 
> _______________________________________________
> Davinci-linux-open-source mailing list
> 
> 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 

  • Previous message:
  • Next message:
  • Messages sorted by:


阅读(1950) | 评论(0) | 转发(0) |
0

上一篇:select()函数用法

下一篇:linux终端命令精选

给主人留下些什么吧!~~