This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

saving H264 stream to local file failed

Hi,

I am using IPNC RDK 3.8 on DM8127. I modified the ENC_A8_DEC usecase to save H264 stream to local file. Related source code is as the following.

Void *MultiCh_ipcBitsMain(Void *prm)
{
    UInt32 i;
    OSA_DmaCopy1D copy1D;
    Bitstream_BufList fullBitsBufList;
    Bitstream_BufList emptyBitsBufList;
    IpcBitsOutLinkHLOS_BitstreamBufReqInfo ipcReqInfo;

    OSA_printf("Entered IPC Bits Handler function\n");
    gIpcBitsThObj.exitTh   = FALSE;
    gIpcBitsThObj.exitDone = FALSE;

    //unsigned char const start_code[4] = { 0x00, 0x00, 0x00, 0x01 };
    FILE  *outFile  = NULL;
    FILE  *outFile2  = NULL;
    UInt8 *buf = NULL;
    UInt32 n   = 0;

    if(outFile == NULL)
    {
    	outFile = fopen("8127Test.h264", "w");
        if (outFile == NULL) {
    		OSA_printf("Failed to open file for writing\n");
                exit(0);
        }
    }

    if(outFile2 == NULL)
    {
    	outFile2 = fopen("8127Test.hdr", "w");
        if (outFile2 == NULL) {
    		OSA_printf("Failed to open file for writing\n");
                exit(0);
        }
    }

    while(gIpcBitsThObj.exitTh == FALSE)
    {
        OSA_semWait(&gIpcBitsNotifySem,OSA_TIMEOUT_FOREVER);

        IpcBitsInLink_getFullVideoBitStreamBufs(gIpcBitsInHLOSId,&fullBitsBufList);

        if(fullBitsBufList.numBufs > 0)
        {
            for(i = 0;i < fullBitsBufList.numBufs;i++)
            {
                ipcReqInfo.numBufs       = 1;
                ipcReqInfo.minBufSize[0] = DEC_MIN_BUF_SIZE;

                /* Wait till empty buffer is got from IPC Bits Out link */
                do
                {
                    IpcBitsOutLink_getEmptyVideoBitStreamBufs(gIpcBitsOutHLOSId,&emptyBitsBufList,&ipcReqInfo);
                    OSA_waitMsecs(10);
                }while(emptyBitsBufList.numBufs == 0);

                /* Copy bitstream */
                emptyBitsBufList.numBufs = 1;
                emptyBitsBufList.bufs[0]->channelNum = fullBitsBufList.bufs[i]->channelNum;
                emptyBitsBufList.bufs[0]->fillLength = fullBitsBufList.bufs[i]->fillLength;
                emptyBitsBufList.bufs[0]->timeStamp  = fullBitsBufList.bufs[i]->timeStamp;

                if(gDmaHndl.chId == 0xFF)
                {
                    memcpy(emptyBitsBufList.bufs[0]->addr,
                           (fullBitsBufList.bufs[i]->addr + fullBitsBufList.bufs[i]->startOffset),
                           fullBitsBufList.bufs[i]->fillLength);
                }
                else
                {
                    copy1D.srcPhysAddr = (unsigned long)CMEM_getPhys(fullBitsBufList.bufs[i]->addr + fullBitsBufList.bufs[i]->startOffset);
                    copy1D.dstPhysAddr = (unsigned long)CMEM_getPhys(emptyBitsBufList.bufs[0]->addr);
                    copy1D.size        = fullBitsBufList.bufs[i]->fillLength;
                    OSA_dmaCopy1D(&gDmaHndl,&copy1D,1);
                }

#if 1
		buf = fullBitsBufList.bufs[i]->addr + fullBitsBufList.bufs[i]->startOffset;
		if (fwrite(buf, fullBitsBufList.bufs[i]->fillLength, 1, outFile) != 1) {
    			OSA_printf("Failed to write data to file\n");
                	exit(0);
                }
#endif
		fprintf(outFile2, "%d, ", fullBitsBufList.bufs[i]->fillLength);
		n++;

		if(n % 100 == 0)
    			OSA_printf("received %d frames.\n", n);

		if(n == 3000)
		{
			fclose(outFile);
			fclose(outFile2);
			exit(0);
		}

                IpcBitsOutLink_putFullVideoBitStreamBufs(gIpcBitsOutHLOSId,&emptyBitsBufList);
            }
        }

        IpcBitsInLink_putEmptyVideoBitStreamBufs(gIpcBitsInHLOSId,&fullBitsBufList);
    }

    gIpcBitsThObj.exitDone = TRUE;

    OSA_printf("Exiting IPC Bits Handler function\n");

    return NULL;
}

When I run the program,  about 2500 frames are saved successfully. Then this thread seems to be locked and no more output is seen. The log is like this:

Starting syslogd/klogd: done

_____ _____ _ _
| _ |___ ___ ___ ___ | _ |___ ___ |_|___ ___| |_
| | _| .'| . | . | | __| _| . | | | -_| _| _|
|__|__|_| |__,|_ |___| |__| |_| |___|_| |___|___|_|
|___| |___|

Arago Project http://arago-project.org DM8127_IPNC ttyO0

Arago 2011.09 DM8127_IPNC ttyO0

DM8127_IPNC login: root (automatic login)
root@DM8127_IPNC:~# mkdosfs 3.0.12 (29 Oct 2011)
unable to get drive geometry, using default 255/63
/dev/sbulla has 255 heads and 63 sectors per track,
logical sector size is 512,
using 0xf8 media descriptor, with 1024 sectors;
file system has 2 12-bit FATs and 4 sectors per cluster.
FAT size is 1 sector, and provides 247 clusters.
There is 1 reserved sector.
Root directory contains 512 slots and uses 32 sectors.
Volume ID is 63107077, no volume label.
g_file_storage gadget: No serial-number string provided!
g_file_storage gadget: File-backed Storage Gadget, version: 1 September 2010
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, nofua=0, file: /dev/sbulla
[m3vpss ] CT: 5592, 3dlut index:2
Simple mixer control 'PGA',0
Capabilities: cvolume cswitch penum
Capture channels: Front Left - Front Right
Limits: Capture 0 - 119
Front Left: Capture 80 [67%] [40.00dB] [on]
Front Right: Capture 80 [67%] [40.00dB] [on]
queue id:0
[m3vpss ] CT: 6091, 3dlut index:3

[host] received 100 frames.
./boa: /usr/lib/libssl.so.1.0.0: no version information available (required by ./boa)
./boa: /usr/lib/libcrypto.so.1.0.0: no version information available (required by ./boa)
ApproDrvInit: 3
queue id:163845
queue id:0
queue id:32769
queue id:0

[host] received 200 frames.

[host] received 300 frames.

[host] received 400 frames.

[host] received 500 frames.

[host] received 600 frames.
TimeOut occure in boot_proc.
Program exit.

[host] received 700 frames.
TimeOut occure in boot_proc.
Program exit.

[host] received 800 frames.

[host]
Usecase is Active !!!

[host] received 900 frames.

[host] received 1000 frames.

[host] received 1100 frames.

[host] received 1200 frames.

[host] received 1300 frames.

[host] received 1400 frames.

[host] received 1500 frames.

[host] received 1600 frames.

[host] received 1700 frames.
[m3vpss ] 66182: CAMERA: Fields = 1801 (fps = 30), Total Resets = 0 (Avg 0 ms per reset)
[m3video] ==================== EncLink_PrintDetails ====================
[m3video] 67020: HDVICP-ID:0
[m3video] totalAcquire2wait in msec: 1125
[m3video] totalWait2Isr in msec: 45929
[m3video] totalIsr2Done in msec: 65
[m3video] totalWait2Done in msec: 45994
[m3video] totalDone2Release in msec: 0
[m3video] totalAcquire2Release in msec: 47715
[m3video] totalAcq2acqDelay in msec: 13053
[m3video] totalElapsedTime in msec: 60767
[m3video] numAccessCnt: 3567
[m3video] IVA-FPS : 59
[m3video]
[m3video] *** ENCODE Statistics ***
[m3video]
[m3video] Elasped Time : 60 secs
[m3video]
[m3video]
[m3video] CH | In Recv In Skip In User Out Latency
[m3video] Num | FPS FPS Skip FPS FPS Min / Max
[m3video] --------------------------------------------
[m3video] 0 | 30 0 0 29.67 14 / 56
[m3video]
[m3video] Multi Channel Encode Average Submit Batch Size
[m3video] Max Submit Batch Size : 24
[m3video] IVAHD_0 Average Batch Size : 1
[m3video] IVAHD_0 Max achieved Batch Size : 1
[m3video] ==============================================================

[host]
Usecase is Active !!!

[host] received 1800 frames.

[host] received 1900 frames.
ApproDrvExit: 7
Error: WaitStreamReady Fail.
Error: SemWait: Invalid Semaphore handler
Error: SemRelease: Invalid Semaphore handler
Error: SemWait: Invalid Semaphore handler

[host]
Force IDR on Channel: 0
[host]
Force IDR on Channel: 1Error: SemRelease: Invalid Semaphore handler
SystemInit success
Schedule manager init success
Dmva Schedule manager init success
umount: can't umount /mnt/mmc: Invalid argument
killall: dhcpcd: no process killed
rm: cannot remove '/var/run/dhcpcd-eth0.pid': No such file or directory

[host] received 2000 frames.

[host] received 2100 frames.

[host] received 2200 frames.

[host] received 2300 frames.

[host] received 2400 frames.

[host] received 2500 frames.

[host]
Usecase is Active !!!
[m3vpss ] ==================== CameraLink_PrintDetails ====================
[m3vpss ] 126123: CAMERA: Fields = 3601 (fps = 30, CPU Load = 27)
[m3vpss ] 126123: CAMERA: Num Resets = 0 (Avg 0 ms per reset)
[m3vpss ] =================================================================
[m3vpss ] 126189: CAMERA: Fields = 1801 (fps = 30), Total Resets = 0 (Avg 0 ms per reset)

[host]
Usecase is Active !!!

[host]
Usecase is Active !!!
[m3video] ==================== EncLink_PrintDetails ====================
[m3video] 161645: HDVICP-ID:0
[m3video] totalAcquire2wait in msec: 1618
[m3video] totalWait2Isr in msec: 65598
[m3video] totalIsr2Done in msec: 80
[m3video] totalWait2Done in msec: 65678
[m3video] totalDone2Release in msec: 0
[m3video] totalAcquire2Release in msec: 68152
[m3video] totalAcq2acqDelay in msec: 18103
[m3video] totalElapsedTime in msec: 86242
[m3video] numAccessCnt: 5095
[m3video] IVA-FPS : 59
[m3video]
[m3video] *** ENCODE Statistics ***
[m3video]
[m3video] Elasped Time : 94 secs
[m3video]
[m3video]
[m3video] CH | In Recv In Skip In User Out Latency
[m3video] Num | FPS FPS Skip FPS FPS Min / Max
[m3video] --------------------------------------------
[m3video] 0 | 30 22 0 8.14 14 / 29
[m3video]
[m3video] Multi Channel Encode Average Submit Batch Size
[m3video] Max Submit Batch Size : 24
[m3video] IVAHD_0 Average Batch Size : 1
[m3video] IVAHD_0 Max achieved Batch Size : 1
[m3video] ==============================================================
net_search_gateway:eth0, 1A8C0, 0, 1
dns=192.168.1.1
net_search_gateway:eth0, 1A8C0, 0, 1
net_search_gateway:eth0, 0, FE01A8C0, 3
dns=192.168.1.1
g_file_storage gadget: No serial-number string provided!
g_file_storage gadget: File-backed Storage Gadget, version: 1 September 2010
g_file_storage gadget: Number of LUNs=1
g_file_storage gadget-lun0: ro=0, nofua=0, file: /dev/sbulla
[09/Nov/2012:12:25:24 +0000] boa: server version Boa/0.94.13
[09/Nov/2012:12:25:24 +0000] boa: server built Aug 19 2014 at 09:27:37.
[09/Nov/2012:12:25:24 +0000] boa: starting server pid=549, port 80
queue id:0
<UDN>uuid:Upnp-TVEmulator-1_0-00_0095591997</UDN>

In other words, I can not save 3000 frames continuously. What is wrong?