PageRenderTime 43ms CodeModel.GetById 14ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

/H264Dec/source/Broadway.c

http://github.com/mbebenita/Broadway
C | 841 lines | 491 code | 129 blank | 221 comment | 102 complexity | 29d2fbed65036c7f9eda5c1eadd9f218 MD5 | raw file
  1/*
  2 * Copyright (C) 2009 The Android Open Source Project
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License");
  5 * you may not use this file except in compliance with the License.
  6 * You may obtain a copy of the License at
  7 *
  8 *      http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS,
 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13 * See the License for the specific language governing permissions and
 14 * limitations under the License.
 15 */
 16
 17#include "H264SwDecApi.h"
 18#include <stdio.h>
 19#include <stdlib.h>
 20#include <string.h>
 21
 22#include "SDL/SDL.h"
 23
 24/*------------------------------------------------------------------------------
 25    Module defines
 26------------------------------------------------------------------------------*/
 27
 28/* CHECK_MEMORY_USAGE prints and sums the memory allocated in calls to
 29 * H264SwDecMalloc() */
 30/* #define CHECK_MEMORY_USAGE */
 31
 32/* _NO_OUT disables output file writing */
 33/* #define _NO_OUT */
 34
 35/* Debug prints */
 36#define DEBUG(argv) // printf argv
 37
 38/* CVS tag name for identification */
 39const char tagName[256] = "$Name: FIRST_ANDROID_COPYRIGHT $";
 40
 41u32 NextPacket(u8 **pStrm);
 42u32 CropPicture(u8 *pOutImage, u8 *pInImage,
 43    u32 picWidth, u32 picHeight, CropParams *pCropParams);
 44
 45/* Global variables for stream handling */
 46u8 *streamStop = NULL;
 47u32 packetize = 0;
 48u32 nalUnitStream = 0;
 49FILE *foutput = NULL;
 50
 51#define RENDER 1
 52void DrawOutput(u8 *data, u32 picWidth, u32 picHeight);
 53SDL_Surface* screen = NULL;
 54
 55// Main loop handling
 56
 57enum mainLoopStatus {
 58  MLS_STOP = 0,
 59  MLS_CONTINUE = 1,
 60  MLS_FRAMERENDERED = 2
 61};
 62
 63// Runs the main loop. This is replaced in JavaScript with an asynchronous loop
 64// that calls mainLoopIteration
 65void runMainLoop();
 66int mainLoopIteration();
 67
 68
 69
 70#ifdef SOC_DESIGNER
 71
 72// Initialisation function defined in InitCache.s
 73extern void cache_init(void);
 74
 75/*------------------------------------------------------------------------------
 76
 77    Function name:  $Sub$$main
 78
 79    Purpose:
 80        This function is called at the end of the C library initialisation and
 81        before main. Its purpose is to do any further initialisation before the
 82        application start.
 83
 84------------------------------------------------------------------------------*/
 85int $Sub$$main(char argc, char * argv[])
 86{
 87  cache_init();                    // does some extra setup work setting up caches
 88  return $Super$$main(argc, argv); // calls the original function
 89}
 90#endif
 91
 92/*------------------------------------------------------------------------------
 93
 94    Function name:  main
 95
 96    Purpose:
 97        main function of decoder testbench. Provides command line interface
 98        with file I/O for H.264 decoder. Prints out the usage information
 99        when executed without arguments.
100
101------------------------------------------------------------------------------*/
102
103u32 i, tmp;
104u32 maxNumPics = 0;
105u8 *byteStrmStart;
106u8 *imageData;
107u8 *tmpImage = NULL;
108u32 strmLen;
109u32 picSize;
110H264SwDecRet ret;
111H264SwDecInst decInst;
112H264SwDecInput decInput;
113H264SwDecOutput decOutput;
114H264SwDecPicture decPicture;
115H264SwDecInfo decInfo;
116H264SwDecApiVersion decVer;
117u32 picDecodeNumber;
118u32 picDisplayNumber;
119u32 numErrors = 0;
120u32 cropDisplay = 0;
121u32 disableOutputReordering = 0;
122
123void runMainLoop() {
124    int status;
125    do {
126        mainLoopIteration();
127    /* keep decoding until all data from input stream buffer consumed */
128    } while (decInput.dataLen > 0);
129
130    // while ((status = mainLoopIteration()) != MLS_STOP);
131}
132
133#ifdef LINUX
134int main(int argc, char **argv) {
135#else
136int SDL_main(int argc, char **argv) {
137#endif
138
139
140
141    FILE *finput;
142
143    char outFileName[256] = "";
144
145    /* Print API version number */
146    decVer = H264SwDecGetAPIVersion();
147    DEBUG(("H.264 Decoder API v%d.%d\n", decVer.major, decVer.minor));
148
149    /* Print tag name if '-T' argument present */
150    if ( argc > 1 && strcmp(argv[1], "-T") == 0 )
151    {
152        DEBUG(("%s\n", tagName));
153        return 0;
154    }
155
156    /* Check that enough command line arguments given, if not -> print usage
157     * information out */
158    if (argc < 2)
159    {
160        DEBUG((
161            "Usage: %s [-Nn] [-Ooutfile] [-P] [-U] [-C] [-R] [-T] file.h264\n",
162            argv[0]));
163        DEBUG(("\t-Nn forces decoding to stop after n pictures\n"));
164#if defined(_NO_OUT)
165        DEBUG(("\t-Ooutfile output writing disabled at compile time\n"));
166#else
167        DEBUG(("\t-Ooutfile write output to \"outfile\" (default out_wxxxhyyy.yuv)\n"));
168        DEBUG(("\t-Onone does not write output\n"));
169#endif
170        DEBUG(("\t-P packet-by-packet mode\n"));
171        DEBUG(("\t-U NAL unit stream mode\n"));
172        DEBUG(("\t-C display cropped image (default decoded image)\n"));
173        DEBUG(("\t-R disable DPB output reordering\n"));
174        DEBUG(("\t-T to print tag name and exit\n"));
175        return 0;
176    }
177
178    /* read command line arguments */
179    for (i = 1; i < (u32)(argc-1); i++)
180    {
181        if ( strncmp(argv[i], "-N", 2) == 0 )
182        {
183            maxNumPics = (u32)atoi(argv[i]+2);
184        }
185        else if ( strncmp(argv[i], "-O", 2) == 0 )
186        {
187            strcpy(outFileName, argv[i]+2);
188        }
189        else if ( strcmp(argv[i], "-P") == 0 )
190        {
191            packetize = 1;
192        }
193        else if ( strcmp(argv[i], "-U") == 0 )
194        {
195            nalUnitStream = 1;
196        }
197        else if ( strcmp(argv[i], "-C") == 0 )
198        {
199            cropDisplay = 1;
200        }
201        else if ( strcmp(argv[i], "-R") == 0 )
202        {
203            disableOutputReordering = 1;
204        }
205    }
206
207    /* open input file for reading, file name given by user. If file open
208     * fails -> exit */
209    finput = fopen(argv[argc-1],"rb");
210    if (finput == NULL)
211    {
212        DEBUG(("UNABLE TO OPEN INPUT FILE\n"));
213        return -1;
214    }
215
216    /* check size of the input file -> length of the stream in bytes */
217    fseek(finput,0L,SEEK_END);
218    strmLen = (u32)ftell(finput);
219    rewind(finput);
220
221    /* allocate memory for stream buffer. if unsuccessful -> exit */
222    byteStrmStart = (u8 *)malloc(sizeof(u8)*strmLen);
223    if (byteStrmStart == NULL)
224    {
225        DEBUG(("UNABLE TO ALLOCATE MEMORY\n"));
226        return -1;
227    }
228
229    /* read input stream from file to buffer and close input file */
230    fread(byteStrmStart, sizeof(u8), strmLen, finput);
231    fclose(finput);
232
233    /* initialize decoder. If unsuccessful -> exit */
234    ret = H264SwDecInit(&decInst, disableOutputReordering);
235    if (ret != H264SWDEC_OK)
236    {
237        DEBUG(("DECODER INITIALIZATION FAILED\n"));
238        free(byteStrmStart);
239        return -1;
240    }
241
242#if RENDER
243    SDL_Init(SDL_INIT_VIDEO);
244#endif
245
246    DEBUG(("DECODING strmLen: %d\n", strmLen));
247
248    /* initialize H264SwDecDecode() input structure */
249    streamStop = byteStrmStart + strmLen;
250    decInput.pStream = byteStrmStart;
251    decInput.dataLen = strmLen;
252    decInput.intraConcealmentMethod = 0;
253
254    /* get pointer to next packet and the size of packet
255     * (for packetize or nalUnitStream modes) */
256    if ( (tmp = NextPacket(&decInput.pStream)) != 0 )
257        decInput.dataLen = tmp;
258
259    picDecodeNumber = picDisplayNumber = 1;
260
261    /* main decoding loop */
262    runMainLoop();
263    return 0;
264}
265
266int terminate() {
267    /* if output in display order is preferred, the decoder shall be forced
268     * to output pictures remaining in decoded picture buffer. Use function
269     * H264SwDecNextPicture() to obtain next picture in display order. Function
270     * is called until no more images are ready for display. Second parameter
271     * for the function is set to '1' to indicate that this is end of the
272     * stream and all pictures shall be output */
273    while (H264SwDecNextPicture(decInst, &decPicture, 1) == H264SWDEC_PIC_RDY)
274    {
275        DEBUG(("PIC %d, type %s", picDisplayNumber,
276            decPicture.isIdrPicture ? "IDR" : "NON-IDR"));
277        if (picDisplayNumber != decPicture.picId)
278            DEBUG((", decoded pic %d", decPicture.picId));
279        if (decPicture.nbrOfErrMBs)
280        {
281            DEBUG((", concealed %d\n", decPicture.nbrOfErrMBs));
282        }
283        else
284            DEBUG(("\n"));
285
286        numErrors += decPicture.nbrOfErrMBs;
287
288        /* Increment display number for every displayed picture */
289        picDisplayNumber++;
290
291        /* Write output picture to file */
292        imageData = (u8*)decPicture.pOutputPicture;
293        if (cropDisplay && decInfo.croppingFlag)
294        {
295            tmp = CropPicture(tmpImage, imageData,
296                decInfo.picWidth, decInfo.picHeight,
297                &decInfo.cropParams);
298            if (tmp)
299                return -1;
300            DrawOutput(tmpImage, decInfo.picWidth, decInfo.picHeight);
301        }
302        else
303        {
304            DrawOutput(imageData, decInfo.picWidth, decInfo.picHeight);
305        }
306    }
307
308#if RENDER
309        SDL_Quit();
310#endif
311
312    /* release decoder instance */
313    H264SwDecRelease(decInst);
314
315    if (foutput)
316        fclose(foutput);
317
318    /* free allocated buffers */
319    free(byteStrmStart);
320    free(tmpImage);
321
322    DEBUG(("DECODING DONE\n"));
323    if (numErrors || picDecodeNumber == 1)
324    {
325        DEBUG(("ERRORS FOUND\n"));
326        return 1;
327    }
328
329    return 0;
330}
331
332int mainLoopIteration() {
333    /* Picture ID is the picture number in decoding order */
334    decInput.picId = picDecodeNumber;
335
336    /* call API function to perform decoding */
337    ret = H264SwDecDecode(decInst, &decInput, &decOutput);
338
339    switch(ret)
340    {
341
342        case H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY:
343            /* Stream headers were successfully decoded
344             * -> stream information is available for query now */
345
346            ret = H264SwDecGetInfo(decInst, &decInfo);
347            if (ret != H264SWDEC_OK)
348                return -1;
349
350            DEBUG(("Profile %d\n", decInfo.profile));
351
352            DEBUG(("Width %d Height %d\n",
353                decInfo.picWidth, decInfo.picHeight));
354
355#if RENDER
356            if (!screen) {
357                screen = SDL_SetVideoMode(decInfo.picWidth, decInfo.picHeight, 32, SDL_HWSURFACE | SDL_RESIZABLE);
358            }
359#endif
360
361            if (cropDisplay && decInfo.croppingFlag)
362            {
363                DEBUG(("Cropping params: (%d, %d) %dx%d\n",
364                    decInfo.cropParams.cropLeftOffset,
365                    decInfo.cropParams.cropTopOffset,
366                    decInfo.cropParams.cropOutWidth,
367                    decInfo.cropParams.cropOutHeight));
368
369                /* Cropped frame size in planar YUV 4:2:0 */
370                picSize = decInfo.cropParams.cropOutWidth *
371                          decInfo.cropParams.cropOutHeight;
372                picSize = (3 * picSize)/2;
373                tmpImage = malloc(picSize);
374                if (tmpImage == NULL)
375                    return -1;
376            }
377            else
378            {
379                /* Decoder output frame size in planar YUV 4:2:0 */
380                picSize = decInfo.picWidth * decInfo.picHeight;
381                picSize = (3 * picSize)/2;
382            }
383
384            DEBUG(("videoRange %d, matrixCoefficients %d\n",
385                decInfo.videoRange, decInfo.matrixCoefficients));
386
387            /* update H264SwDecDecode() input structure, number of bytes
388             * "consumed" is computed as difference between the new stream
389             * pointer and old stream pointer */
390            decInput.dataLen -=
391                (u32)(decOutput.pStrmCurrPos - decInput.pStream);
392            decInput.pStream = decOutput.pStrmCurrPos;
393            break;
394
395        case H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY:
396            /* Picture is ready and more data remains in input buffer
397             * -> update H264SwDecDecode() input structure, number of bytes
398             * "consumed" is computed as difference between the new stream
399             * pointer and old stream pointer */
400            decInput.dataLen -=
401                (u32)(decOutput.pStrmCurrPos - decInput.pStream);
402            decInput.pStream = decOutput.pStrmCurrPos;
403            /* fall through */
404
405        case H264SWDEC_PIC_RDY:
406
407            /*lint -esym(644,tmpImage,picSize) variable initialized at
408             * H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY case */
409
410            if (ret == H264SWDEC_PIC_RDY)
411                decInput.dataLen = NextPacket(&decInput.pStream);
412
413            /* If enough pictures decoded -> force decoding to end
414             * by setting that no more stream is available */
415            if (maxNumPics && picDecodeNumber == maxNumPics)
416                decInput.dataLen = 0;
417
418            /* Increment decoding number for every decoded picture */
419            picDecodeNumber++;
420
421            /* use function H264SwDecNextPicture() to obtain next picture
422             * in display order. Function is called until no more images
423             * are ready for display */
424            while ( H264SwDecNextPicture(decInst, &decPicture, 0) ==
425                    H264SWDEC_PIC_RDY )
426            {
427                DEBUG(("PIC %d, type %s", picDisplayNumber,
428                    decPicture.isIdrPicture ? "IDR" : "NON-IDR"));
429                if (picDisplayNumber != decPicture.picId)
430                    DEBUG((", decoded pic %d", decPicture.picId));
431                if (decPicture.nbrOfErrMBs)
432                {
433                    DEBUG((", concealed %d\n", decPicture.nbrOfErrMBs));
434                }
435                else
436                    DEBUG(("\n"));
437
438                numErrors += decPicture.nbrOfErrMBs;
439
440                /* Increment display number for every displayed picture */
441                picDisplayNumber++;
442
443                /*lint -esym(644,decInfo) always initialized if pictures
444                 * available for display */
445
446                /* Write output picture to file */
447                imageData = (u8*)decPicture.pOutputPicture;
448                if (cropDisplay && decInfo.croppingFlag)
449                {
450                    tmp = CropPicture(tmpImage, imageData,
451                        decInfo.picWidth, decInfo.picHeight,
452                        &decInfo.cropParams);
453                    if (tmp)
454                        return -1;
455                    DrawOutput(tmpImage, decInfo.picWidth, decInfo.picHeight);
456                }
457                else
458                {
459                    DrawOutput(imageData, decInfo.picWidth, decInfo.picHeight);
460                }
461            }
462
463            break;
464
465        case H264SWDEC_STRM_PROCESSED:
466        case H264SWDEC_STRM_ERR:
467            /* Input stream was decoded but no picture is ready
468             * -> Get more data */
469            decInput.dataLen = NextPacket(&decInput.pStream);
470            break;
471
472        default:
473            DEBUG(("FATAL ERROR\n"));
474            return -1;
475
476    }
477}
478
479void paint(u8 *luma, u8 *cb, u8 *cr, int width, int height) {
480    SDL_LockSurface(screen);
481
482    int chromaWidth = width >> 1;
483    u32 *dst = (u32 *)screen->pixels;
484    int x, y = 0;
485    for (y = 0; y < height; y++) {
486        int lineOffLuma = y * width;
487        int lineOffChroma = (y >> 1) * chromaWidth;
488        for (x = 0; x < width; x++) {
489            int c = luma[lineOffLuma + x] - 16;
490            int d = cb[lineOffChroma + (x >> 1)] - 128;
491            int e = cr[lineOffChroma + (x >> 1)] - 128;
492
493            int red = (298 * c + 409 * e + 128) >> 8;
494            red = red < 0 ? 0 : (red > 255 ? 255 : red);
495            int green = (298 * c - 100 * d - 208 * e + 128) >> 8;
496            green = green < 0 ? 0 : (green > 255 ? 255 : green);
497            int blue = (298 * c + 516 * d + 128) >> 8;
498            blue = blue < 0 ? 0 : (blue > 255 ? 255 : blue);
499            int alpha = 255;
500            dst[lineOffLuma + x] = SDL_MapRGB(screen->format, red & 0xff, green & 0xff, blue & 0xff);
501        }
502    }
503
504    SDL_UnlockSurface(screen);
505    SDL_Flip(screen);
506}
507
508
509void broadwayOnFrameDecoded() { }
510
511void broadwaySetPosition(float position) {
512    printf("SetPosition %f\n", position);
513}
514
515float broadwayGetPosition() {
516    printf("GetPosition\n");
517    return 0;
518}
519
520void DrawOutput(u8 *data, u32 picWidth, u32 picHeight) {
521    u32 size = picWidth * picHeight;
522#if RENDER
523    paint(data, data + size, data + size + (size >> 2), picWidth, picHeight);
524    broadwayOnFrameDecoded();
525#endif
526
527#if !JS
528    SDL_Event event;
529    while (SDL_PollEvent(&event)) {
530        switch (event.type) {
531        case SDL_QUIT:
532            exit(0);
533            break;
534        case SDL_KEYDOWN:
535            exit(0);
536            break;
537        }
538    }
539#endif
540
541}
542
543/*------------------------------------------------------------------------------
544
545    Function name: NextDacket
546
547    Purpose:
548        Get the pointer to start of next packet in input stream. Uses
549        global variables 'packetize' and 'nalUnitStream' to determine the
550        decoder input stream mode and 'streamStop' to determine the end
551        of stream. There are three possible stream modes:
552            default - the whole stream at once
553            packetize - a single NAL-unit with start code prefix
554            nalUnitStream - a single NAL-unit without start code prefix
555
556        pStrm stores pointer to the start of previous decoder input and is
557        replaced with pointer to the start of the next decoder input.
558
559        Returns the packet size in bytes
560
561------------------------------------------------------------------------------*/
562u32 NextPacket(u8 **pStrm)
563{
564
565    u32 index;
566    u32 maxIndex;
567    u32 zeroCount;
568    u8 *stream;
569    u8 byte;
570    static u32 prevIndex=0;
571
572    /* For default stream mode all the stream is in first packet */
573    if (!packetize && !nalUnitStream)
574        return 0;
575
576    index = 0;
577    stream = *pStrm + prevIndex;
578    maxIndex = (u32)(streamStop - stream);
579
580    if (maxIndex == 0)
581        return(0);
582
583    /* leading zeros of first NAL unit */
584    do
585    {
586        byte = stream[index++];
587    } while (byte != 1 && index < maxIndex);
588
589    /* invalid start code prefix */
590    if (index == maxIndex || index < 3)
591    {
592        DEBUG(("INVALID BYTE STREAM\n"));
593        exit(100);
594    }
595
596    /* nalUnitStream is without start code prefix */
597    if (nalUnitStream)
598    {
599        stream += index;
600        maxIndex -= index;
601        index = 0;
602    }
603
604    zeroCount = 0;
605
606    /* Search stream for next start code prefix */
607    /*lint -e(716) while(1) used consciously */
608    while (1)
609    {
610        byte = stream[index++];
611        if (!byte)
612            zeroCount++;
613
614        if ( (byte == 0x01) && (zeroCount >= 2) )
615        {
616            /* Start code prefix has two zeros
617             * Third zero is assumed to be leading zero of next packet
618             * Fourth and more zeros are assumed to be trailing zeros of this
619             * packet */
620            if (zeroCount > 3)
621            {
622                index -= 4;
623                zeroCount -= 3;
624            }
625            else
626            {
627                index -= zeroCount+1;
628                zeroCount = 0;
629            }
630            break;
631        }
632        else if (byte)
633            zeroCount = 0;
634
635        if (index == maxIndex)
636        {
637            break;
638        }
639
640    }
641
642    /* Store pointer to the beginning of the packet */
643    *pStrm = stream;
644    prevIndex = index;
645
646    /* nalUnitStream is without trailing zeros */
647    if (nalUnitStream)
648        index -= zeroCount;
649
650    return(index);
651
652}
653
654/*------------------------------------------------------------------------------
655
656    Function name: CropPicture
657
658    Purpose:
659        Perform cropping for picture. Input picture pInImage with dimensions
660        picWidth x picHeight is cropped with pCropParams and the resulting
661        picture is stored in pOutImage.
662
663------------------------------------------------------------------------------*/
664u32 CropPicture(u8 *pOutImage, u8 *pInImage,
665    u32 picWidth, u32 picHeight, CropParams *pCropParams)
666{
667
668    u32 i, j;
669    u32 outWidth, outHeight;
670    u8 *pOut, *pIn;
671
672    if (pOutImage == NULL || pInImage == NULL || pCropParams == NULL ||
673        !picWidth || !picHeight)
674    {
675        /* just to prevent lint warning, returning non-zero will result in
676         * return without freeing the memory */
677        free(pOutImage);
678        return(1);
679    }
680
681    if ( ((pCropParams->cropLeftOffset + pCropParams->cropOutWidth) >
682           picWidth ) ||
683         ((pCropParams->cropTopOffset + pCropParams->cropOutHeight) >
684           picHeight ) )
685    {
686        /* just to prevent lint warning, returning non-zero will result in
687         * return without freeing the memory */
688        free(pOutImage);
689        return(1);
690    }
691
692    outWidth = pCropParams->cropOutWidth;
693    outHeight = pCropParams->cropOutHeight;
694
695    /* Calculate starting pointer for luma */
696    pIn = pInImage + pCropParams->cropTopOffset*picWidth +
697        pCropParams->cropLeftOffset;
698    pOut = pOutImage;
699
700    /* Copy luma pixel values */
701    for (i = outHeight; i; i--)
702    {
703        for (j = outWidth; j; j--)
704        {
705            *pOut++ = *pIn++;
706        }
707        pIn += picWidth - outWidth;
708    }
709
710    outWidth >>= 1;
711    outHeight >>= 1;
712
713    /* Calculate starting pointer for cb */
714    pIn = pInImage + picWidth*picHeight +
715        pCropParams->cropTopOffset*picWidth/4 + pCropParams->cropLeftOffset/2;
716
717    /* Copy cb pixel values */
718    for (i = outHeight; i; i--)
719    {
720        for (j = outWidth; j; j--)
721        {
722            *pOut++ = *pIn++;
723        }
724        pIn += picWidth/2 - outWidth;
725    }
726
727    /* Calculate starting pointer for cr */
728    pIn = pInImage + 5*picWidth*picHeight/4 +
729        pCropParams->cropTopOffset*picWidth/4 + pCropParams->cropLeftOffset/2;
730
731    /* Copy cr pixel values */
732    for (i = outHeight; i; i--)
733    {
734        for (j = outWidth; j; j--)
735        {
736            *pOut++ = *pIn++;
737        }
738        pIn += picWidth/2 - outWidth;
739    }
740
741    return (0);
742}
743
744/*------------------------------------------------------------------------------
745
746    Function name:  H264SwDecTrace
747
748    Purpose:
749        Example implementation of H264SwDecTrace function. Prototype of this
750        function is given in H264SwDecApi.h. This implementation appends
751        trace messages to file named 'dec_api.trc'.
752
753------------------------------------------------------------------------------*/
754void H264SwDecTrace(char *string)
755{
756    printf("%s\n", string);
757
758    /*
759    FILE *fp;
760
761    fp = fopen("dec_api.trc", "at");
762
763    if (!fp)
764        return;
765
766    fwrite(string, 1, strlen(string), fp);
767    fwrite("\n", 1,1, fp);
768
769    fclose(fp);
770    */
771}
772
773/*------------------------------------------------------------------------------
774
775    Function name:  H264SwDecMalloc
776
777    Purpose:
778        Example implementation of H264SwDecMalloc function. Prototype of this
779        function is given in H264SwDecApi.h. This implementation uses
780        library function malloc for allocation of memory.
781
782------------------------------------------------------------------------------*/
783void* H264SwDecMalloc(u32 size)
784{
785
786#if defined(CHECK_MEMORY_USAGE)
787    /* Note that if the decoder has to free and reallocate some of the buffers
788     * the total value will be invalid */
789    static u32 numBytes = 0;
790    numBytes += size;
791    DEBUG(("Allocated %d bytes, total %d\n", size, numBytes));
792#endif
793
794    return malloc(size);
795}
796
797/*------------------------------------------------------------------------------
798
799    Function name:  H264SwDecFree
800
801    Purpose:
802        Example implementation of H264SwDecFree function. Prototype of this
803        function is given in H264SwDecApi.h. This implementation uses
804        library function free for freeing of memory.
805
806------------------------------------------------------------------------------*/
807void H264SwDecFree(void *ptr)
808{
809    free(ptr);
810}
811
812/*------------------------------------------------------------------------------
813
814    Function name:  H264SwDecMemcpy
815
816    Purpose:
817        Example implementation of H264SwDecMemcpy function. Prototype of this
818        function is given in H264SwDecApi.h. This implementation uses
819        library function memcpy to copy src to dest.
820
821------------------------------------------------------------------------------*/
822void H264SwDecMemcpy(void *dest, void *src, u32 count)
823{
824    memcpy(dest, src, count);
825}
826
827/*------------------------------------------------------------------------------
828
829    Function name:  H264SwDecMemset
830
831    Purpose:
832        Example implementation of H264SwDecMemset function. Prototype of this
833        function is given in H264SwDecApi.h. This implementation uses
834        library function memset to set content of memory area pointed by ptr.
835
836------------------------------------------------------------------------------*/
837void H264SwDecMemset(void *ptr, i32 value, u32 count)
838{
839    memset(ptr, value, count);
840}
841