MHEG  17.9.0
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Pages
Macros | Typedefs | Enumerations | Functions
stmr_dl.c File Reference

IC Streamer download manager. More...

#include <assert.h>
#include <string.h>
#include "stb_os.h"
#include "glue_memory.h"
#include "glue_debug.h"
#include "glue_queue.h"
#include "http_interface.h"
#include "stmr_dl.h"
#include "stmr_common.h"
#include "http_header.h"
#include "stmr_header.h"
#include "stmr_queue.h"
#include "mh5streamer.h"

Macros

#define INVALID_TIMESTAMP   0xffffffff
 
#define SYNC_BYTE   0x47
 
#define SYNC_COUNT_ACCEPT   20
 
#define SYNC_BUFFER_SIZE   (STMR_TS_PACKET_SIZE * SYNC_COUNT_ACCEPT)
 
#define SYNC_COUNT_MIN_ACCEPT   (SYNC_COUNT_ACCEPT / 2)
 
#define USE_MAGIC
 
#define GOOD_MAGIC   0xdeadbeef
 
#define BAD_MAGIC   0xfefefefe
 
#define SET_MAGIC(r)   do { r->magic = GOOD_MAGIC; } while (0)
 
#define VERIFY_MAGIC(r)   assert(r->magic == GOOD_MAGIC)
 
#define CLEAR_MAGIC(r)   do { r->magic = BAD_MAGIC; } while (0)
 
#define DBG(x)
 
#define PDBG(x)   TRACE(TICS, x)
 

Typedefs

typedef struct sPsiInfo PsiInfo
 
typedef struct sDownloadRequest DownloadRequest
 

Enumerations

enum  SyncState { SYNC_ACCUM, SYNC_FOUND, SYNC_FAILED }
 
enum  PsiState { PSI_STATE_PAT, PSI_STATE_PMT, PSI_STATE_PCR }
 

Functions

U32BIT MHEG5CreateDownloadRequest (U32BIT requestId, char *url, U64BIT rangeFrom, U64BIT rangeTo, BOOLEAN lastRequest)
 Create HTTP download request. More...
 
void MHEG5StartDownloadRequest (U32BIT downloadId)
 Start HTTP download request. More...
 
U8BIT * MHEG5GetDownloadRedirect (U32BIT downloadId)
 Return the redirection URL for a request that was redirected (HTTP status 3xx). More...
 
BOOLEAN MHEG5DownloadPositionPartial (U32BIT downloadId, U64BIT *position)
 Return what is current position of download request. More...
 
U64BIT MHEG5GetDownloadContentLength (U32BIT downloadId, U64BIT contentLength)
 Return content length (in bytes) for download request. The content length may be: More...
 
void MHEG5CopyDownloadBitrate (U32BIT downloadId, U32BIT *bytesPerSecond)
 Copy download bitrate that was obtained from the headers. If the X-BytesPerSecond header were not received, the bitrate is not updated. More...
 
void MHEG5CopyDownloadStreamKeyInfo (U32BIT downloadId, S_ICSKeys *keys, MHEG5String *keyLocation)
 Copy any keys or key location that were obtained from the headers. If such keys or location exist, they are also cleared from the download request (i.e. ownership is transferred to the caller). In addition, the caller keys and key location are also cleared. If such keys or key location does not exist, the function does not overwrite the caller's keys or key location. More...
 
BOOLEAN MHEG5GetDownloadPmt (U32BIT downloadId, U8BIT *pmt)
 Return program map table (PMT) for download (if available). The table is provided as a complete section, including table_id and CRC_32. More...
 
void MHEG5ResumeDownload (void)
 Resume download of the active request. Download may or may not have been paused due to the buffer being full. More...
 
void MHEG5ClearDownloadThrottling (void)
 Clear information about throttling, causing the download to proceed at full speed (until throttling kicks in again). More...
 
void MHEG5StopDownloadRequest (U32BIT downloadId)
 Stop HTTP download request. More...
 
void MHEG5StopDownloadRequestAsync (U32BIT downloadId)
 Stop HTTP download request asynchronously. This function should be used when the caller wants to stop the download from one of the callbacks. In that case the download will be paused and notified as complete. The caller can then handle the event and stop/destroy the request. More...
 
void MHEG5DestroyDownloadRequest (U32BIT downloadId)
 Destroy HTTP download request. More...
 
void MHEG5ClearDownloadRequest (U32BIT downloadId)
 Clear HTTP download request. More...
 
void MHEG5RenewDownloadRequest (U32BIT downloadId, char *url)
 Renew HTTP download request. More...
 

Detailed Description

IC Streamer download manager.

Date
21/10/2010
Author
Omri Barel

Function Documentation

void MHEG5ClearDownloadRequest ( U32BIT  downloadId)

Clear HTTP download request.

Parameters
downloadIdDownload request ID
Returns
Nothing
void MHEG5ClearDownloadThrottling ( void  )

Clear information about throttling, causing the download to proceed at full speed (until throttling kicks in again).

Returns
Nothing
void MHEG5CopyDownloadBitrate ( U32BIT  downloadId,
U32BIT *  bytesPerSecond 
)

Copy download bitrate that was obtained from the headers. If the X-BytesPerSecond header were not received, the bitrate is not updated.

Parameters
downloadIdDownload request ID
bytesPerSecondStream bitrate (bytes per second)
Returns
Nothing
void MHEG5CopyDownloadStreamKeyInfo ( U32BIT  downloadId,
S_ICSKeys keys,
MHEG5String keyLocation 
)

Copy any keys or key location that were obtained from the headers. If such keys or location exist, they are also cleared from the download request (i.e. ownership is transferred to the caller). In addition, the caller keys and key location are also cleared. If such keys or key location does not exist, the function does not overwrite the caller's keys or key location.

Parameters
downloadIdDownload request ID
keysKeys (if any)
keyLocationKey location (if any)
Returns
Nothing
U32BIT MHEG5CreateDownloadRequest ( U32BIT  requestId,
char *  url,
U64BIT  rangeFrom,
U64BIT  rangeTo,
BOOLEAN  lastRequest 
)

Create HTTP download request.

Parameters
requestIdRequest ID to be stored with downloaded items
urlURL for request
rangeFromRange from in bytes (0 for "start")
rangeToRange to in bytes (invalid for "end")
lastRequestWhether this is the last request for this URL
Returns
Donwload ID (non-zero) if request was created, 0 (zero) otherwise
void MHEG5DestroyDownloadRequest ( U32BIT  downloadId)

Destroy HTTP download request.

Parameters
downloadIdDownload request ID
Returns
Nothing
BOOLEAN MHEG5DownloadPositionPartial ( U32BIT  downloadId,
U64BIT position 
)

Return what is current position of download request.

Parameters
downloadIdDownload request ID
positioncurrent position (downloaded bytes)
Returns
TRUE if position is only partial download
U64BIT MHEG5GetDownloadContentLength ( U32BIT  downloadId,
U64BIT  contentLength 
)

Return content length (in bytes) for download request. The content length may be:

  1. The length value from Content-Range
  2. The value of Content-Length
  3. Invalid value (if not available)
    Parameters
    downloadIdDownload request ID
    contentLengthContent length in bytes
    Returns
    Content length in bytes
BOOLEAN MHEG5GetDownloadPmt ( U32BIT  downloadId,
U8BIT *  pmt 
)

Return program map table (PMT) for download (if available). The table is provided as a complete section, including table_id and CRC_32.

Parameters
downloadIdDownload request ID
pmtStorage area for PMT (1024 bytes)
Returns
TRUE if PMT is available, FALSE otherwise
U8BIT* MHEG5GetDownloadRedirect ( U32BIT  downloadId)

Return the redirection URL for a request that was redirected (HTTP status 3xx).

Parameters
downloadIdDownload request ID
Returns
Redirection URL or NULL
void MHEG5RenewDownloadRequest ( U32BIT  downloadId,
char *  url 
)

Renew HTTP download request.

Parameters
downloadIdDownload request ID
Returns
Nothing
void MHEG5ResumeDownload ( void  )

Resume download of the active request. Download may or may not have been paused due to the buffer being full.

Returns
Nothing
void MHEG5StartDownloadRequest ( U32BIT  downloadId)

Start HTTP download request.

Parameters
downloadIdDownload request ID
Returns
Nothing
void MHEG5StopDownloadRequest ( U32BIT  downloadId)

Stop HTTP download request.

Parameters
downloadIdDownload request ID
Returns
Nothing
void MHEG5StopDownloadRequestAsync ( U32BIT  downloadId)

Stop HTTP download request asynchronously. This function should be used when the caller wants to stop the download from one of the callbacks. In that case the download will be paused and notified as complete. The caller can then handle the event and stop/destroy the request.

Parameters
downloadIdDownload request ID
Returns
Nothing