Search code examples
delphidelphi-xe2rtmp

LIBRTMP Delphi RTMP_Read error?


I think that the unit that I'm using is wrong, because I do reading procedure:

procedure ReadStream (rtmp: RTMP; Stream: TStream);
var
   Buffer: array [0 .. 16384-1] of Byte ;/ / 16kB buffer
   BytesRead: Integer;
begin
   while True do
   begin
     BytesRead: = RTMP_ReadData (rtmp, @ Buffer [0], SizeOf (Buffer));
     if BytesRead = 0 then
       exit;
     Stream.WriteBuffer (Buffer [0], BytesRead);
   end;
end;

Procedure call:

var
  MY_RTMP: RTMP;
  URL_str: string;
  MY_RTMPPacket: RTMPPacket;
  URL_char: PAnsiChar;
  F: TFileStream;
begin
  F: = TFileStream.Create (ExtractFilePath (GetModuleName (0)) + 'Video.flv', fmCreate or fmOpenWrite);
  URL_str: = 'rtmp :/ / localhost: 1935/Video/test.stream';
  MY_RTMP: = RTMP_Alloc;
  RTMP_Init (MY_RTMP);
  RTMP_SetupURL (MY_RTMP, pcchar (URL_str));
  RTMP_EnableWrite (MY_RTMP);
  RTMP_Connect (MY_RTMP, MY_RTMPPacket);
  RTMP_ConnectStream (MY_RTMP, 0);
  ReadStream (MY_RTMP, F);
end;

The program compiles, but when you start getting the error message: The procedure entry point RTMP_ReadData not found in library DLL librtmp? But this function is described in the module, help me find a discrepancy

the library does not function RTMP_ReadData, if trust Dependency Walker. There is a function RTMP_Read, and according to the source:

links

function on C as follows:

static int rtmp_read (URLContext * s, uint8_t * buf, int size)
{
     LibRTMPContext * ctx = s-> priv_data;
     RTMP * r = & ctx-> rtmp;

     return RTMP_Read (r, buf, size);
}

and in the module, which I use the description is missing

the module I use an existing entry:

RTMP_READ = record
       buf: pcchar;
       bufpos: pcchar;
       buflen: cuint;
       timestamp: uint32_t;
       dataType: uint8_t;
       flags: uint8_t;
       status: int8_t;
       initialFrameType: uint8_t;
       nResumeTS: uint32_t;
       metaHeader: pcchar;
       initialFrame: pcchar;
       nMetaHeaderSize: uint32_t;
       nInitialFrameSize: uint32_t;
       nIgnoredFrameCounter: uint32_t;
       nIgnoredFlvFrameCounter: uint32_t;
     end;

She imee name that is invoked, but it contains a lot of confusing me options, not related to the function of the load, in my opinion. What do I do with this record?


Solution

  • According to all my research, the function is in fact named RTMP_Read.

    You can check what functions your DLL exports using Dependency Walker, for example. Of course, the definitive source for your library should be the C++ header file that it is supplied with.


    My advice would be to start learning how to use LIBRTMP using C or C++. At the moment you don't know whether errors are due to a bad translation of the interface, or due to calling it incorrectly. If you continue using Delphi then you'll forever be struggling to work out the cause of errors.

    However, switch to C or C++ and you already have the header file that is needed to link to the library. You can compile the demo programs that come with RTMPDUMP and observe how they work. You can use them as your documentation since LIBRTMP itself appears to have none (not that I can find).

    Then, once you understand how the library works, start porting it do Delphi. First of all create the simplest possible C++ program that uses the library. Port that to Delphi. Having a running C++ version of the program to compare against will help you isolate faults.

    Eventually you'll have a functioning Delphi translation of the interface. More importantly you'll actually understand how to call the library. If you carry on down your current path you'll make very slow progress.