-2

我需要一个应用程序,我想在其中将 NAL 单元的字节流提供给 GMFBridge 播放器而不是文件。所以我为演示做了以下操作获取文件并解析文件,以便我可以找到最终单元

   FILE* infile;

    uint8_t* buf = (uint8_t*)malloc(BUFSIZE );
    char* buf1 = new char(BUFSIZE );

    h264_stream_t* h = h264_new();

    /*if (argc < 2) { usage(); return EXIT_FAILURE; }*/
     infile = fopen(Filepath, "rb");
   while (1)
    {
        rsz = fread(buf + sz, 1, BUFSIZE - sz, infile);

    fseek (infile , 0 , SEEK_END);
   lSize = ftell (infile);
   rewind (infile);
   buffer = (char*) malloc (sizeof(char)*lSize);
  if (buffer == NULL)
  {fputs ("Memory error",stderr); exit (2);}

  // copy the file into the buffer:
  result = fread (buffer,1,lSize,infile);
  if (result != lSize) 
  {fputs ("Reading error",stderr); exit (3);}
   fprintf( h264_dbgfile1,"data in file is %lld\n",buffer);
   int l=strlen(buffer);
      fclose (h264_dbgfile1);
  if (rsz == 0)
        {
            if (ferror(infile)) { fprintf( stderr, "!! Error: read failed: %s \n", strerror(errno)); break; }
            break;  // if (feof(infile)) 
        }

        sz += rsz;

        while (find_nal_unit(p, sz, &nal_start, &nal_end) > 0)
{
                   int length =nal_end-nal_start;
            int j=0;
            while(length!=0)
            {

            for (int start=nal_start;start<=nal_end;start++)
            {
                             FileData[pointer][j]=buffer[start];
                //FileData[pointer][j]=(p[j]);
                j++;
                length--;
                if(length==0)
                    break;
            }
            }

HRESULT hr = m_pPlayer->AddClip(ofn.lpstrFile, &pClip);//i am not able to give the data here

请告诉上面的解决方案,或者我们可以连接GMFBridge播放器从socket中获取数据并连续播放。我尝试了套接字,但由于连接调用成功,我没有接收数据

int find_nal_unit(uint8_t* buf, int size, int* nal_start, int* nal_end)
{
    int i;
    // find start
    *nal_start = 0;
    *nal_end = 0;

    i = 0;
    while (   //( next_bits( 24 ) != 0x000001 && next_bits( 32 ) != 0x00000001 )
        (buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) && 
        (buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0 || buf[i+3] != 0x01) 
        )
    {
        i++; // skip leading zero
        if (i+4 >= size) { return 0; } // did not find nal start
    }

    if  (buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) // ( next_bits( 24 ) != 0x000001 )
    {
        i++;
    }

    if  (buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) { /* error, should never happen */ return 0; }
    i+= 3;
    *nal_start = i;

    while (   //( next_bits( 24 ) != 0x000000 && next_bits( 24 ) != 0x000001 )
        (buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0) && 
        (buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) 
        )
    {
        i++;
        // FIXME the next line fails when reading a nal that ends exactly at the end of the data
        if (i+3 >= size) { *nal_end = size; return -1; } // did not find nal end, stream ended first
    }

    *nal_end = i;
    return (*nal_end - *nal_start);
}
4

1 回答 1

1

Bridge 正在连接两个图表,以便您可以独立更改它们的状态,而不会出现不必要的流中断。它与 H.264、套接字和 NAL 单元无关。

如果您找到或创建了一个过滤器,该过滤器可以将从套接字接收的有效负载传递到 DirectShow 管道,桥将能够接受它并将其传递到第二个图中。

于 2012-12-26T13:42:44.020 回答