MHEG5  18.9.0
MHEG5 Documentation
Classes | 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"

Go to the source code of this file.

Classes

struct  sPsiInfo
 
struct  sDownloadRequest
 

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...
 
U8BITMHEG5GetDownloadRedirect (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

Definition in file stmr_dl.c.

Macro Definition Documentation

#define BAD_MAGIC   0xfefefefe

Definition at line 59 of file stmr_dl.c.

#define CLEAR_MAGIC (   r)    do { r->magic = BAD_MAGIC; } while (0)

Definition at line 62 of file stmr_dl.c.

#define DBG (   x)

Definition at line 69 of file stmr_dl.c.

#define GOOD_MAGIC   0xdeadbeef

Definition at line 58 of file stmr_dl.c.

#define INVALID_TIMESTAMP   0xffffffff

Definition at line 49 of file stmr_dl.c.

#define PDBG (   x)    TRACE(TICS, x)

Definition at line 70 of file stmr_dl.c.

#define SET_MAGIC (   r)    do { r->magic = GOOD_MAGIC; } while (0)

Definition at line 60 of file stmr_dl.c.

#define SYNC_BUFFER_SIZE   (STMR_TS_PACKET_SIZE * SYNC_COUNT_ACCEPT)

Definition at line 52 of file stmr_dl.c.

#define SYNC_BYTE   0x47

Definition at line 50 of file stmr_dl.c.

#define SYNC_COUNT_ACCEPT   20

Definition at line 51 of file stmr_dl.c.

#define SYNC_COUNT_MIN_ACCEPT   (SYNC_COUNT_ACCEPT / 2)

Definition at line 53 of file stmr_dl.c.

#define USE_MAGIC

Definition at line 55 of file stmr_dl.c.

#define VERIFY_MAGIC (   r)    assert(r->magic == GOOD_MAGIC)

Definition at line 61 of file stmr_dl.c.

Typedef Documentation

typedef struct sPsiInfo PsiInfo

Enumeration Type Documentation

enum PsiState
Enumerator
PSI_STATE_PAT 
PSI_STATE_PMT 
PSI_STATE_PCR 

Definition at line 82 of file stmr_dl.c.

enum SyncState
Enumerator
SYNC_ACCUM 
SYNC_FOUND 
SYNC_FAILED 

Definition at line 75 of file stmr_dl.c.

Function Documentation

void MHEG5ClearDownloadRequest ( U32BIT  downloadId)

Clear HTTP download request.

Parameters
downloadIdDownload request ID
Returns
Nothing

Definition at line 667 of file stmr_dl.c.

void MHEG5ClearDownloadThrottling ( void  )

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

Returns
Nothing

Definition at line 549 of file stmr_dl.c.

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

Definition at line 416 of file stmr_dl.c.

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

Definition at line 444 of file stmr_dl.c.

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

Definition at line 212 of file stmr_dl.c.

void MHEG5DestroyDownloadRequest ( U32BIT  downloadId)

Destroy HTTP download request.

Parameters
downloadIdDownload request ID
Returns
Nothing

Definition at line 627 of file stmr_dl.c.

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

Definition at line 359 of file stmr_dl.c.

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

Definition at line 394 of file stmr_dl.c.

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

Definition at line 501 of file stmr_dl.c.

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

Definition at line 337 of file stmr_dl.c.

void MHEG5RenewDownloadRequest ( U32BIT  downloadId,
char *  url 
)

Renew HTTP download request.

Parameters
downloadIdDownload request ID
Returns
Nothing

Definition at line 697 of file stmr_dl.c.

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

Definition at line 527 of file stmr_dl.c.

void MHEG5StartDownloadRequest ( U32BIT  downloadId)

Start HTTP download request.

Parameters
downloadIdDownload request ID
Returns
Nothing

Definition at line 317 of file stmr_dl.c.

void MHEG5StopDownloadRequest ( U32BIT  downloadId)

Stop HTTP download request.

Parameters
downloadIdDownload request ID
Returns
Nothing

Definition at line 584 of file stmr_dl.c.

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

Definition at line 609 of file stmr_dl.c.