forked from thegryghost/mlbtv-hls-nexdef
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mlb.h
171 lines (130 loc) · 2.85 KB
/
mlb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#ifndef MLB_HLS_H
#define MLB_HLS_H
#include <stdint.h>
#include <pthread.h>
#include <time.h>
#include <curl/curl.h>
#include "output.h"
#include "utils.h"
#define AES128_KEY_SIZE 16
#define MAX_STR_LEN 1024
#define MLB_KEY_TYPE_AES128 1
#define MLB_HLS_MAX_STREAMS 12
#define MLB_MAX_IV_COUNT 800
#define MLB_HLS_STATE_END 0
#define MLB_HLS_STATE_LIVE 1
#define MLB_HLS_STATE_BAD 2
static const char *MLB_STATE_STRINGS[3] =
{
"End of Playlist",
"Still Live",
"Invalid Playlist"
};
struct mlb_hls_iv_struct
{
int pos;
uint8_t iv[AES128_KEY_SIZE];
uint8_t *aes;
};
typedef struct mlb_hls_iv_struct MLB_HLS_IV_STRUCT;
struct mlb_hls_key
{
int key_len_org;
int key_len_decoded;
uint8_t *key_decoded;
uint8_t *key_org;
};
typedef struct mlb_hls_key MLB_HLS_KEY;
struct mlb_opt_args
{
OUTPUT_STRUCT output;
int bandwidth_max;
int bandwidth_min;
int bandwidth_start;
int lock_bandwidth;
int refresh_time;
int start_pos;
char base64_uri[MAX_STR_LEN];
int verbose;
int launch_wait;
char launch_cmd[MAX_STR_LEN];
char cfg_file[MAX_STR_LEN];
char proxy_addr[MAX_STR_LEN];
};
typedef struct mlb_opt_args MLB_OPT_ARGS;
struct mlb_hls_stream_url
{
CURL *playlist_curl;
CURL *key_curl;
CURLcode res;
uint8_t cache;
int8_t state;
uint8_t key_type;
uint8_t aes_key[AES128_KEY_SIZE];
int iv_count;
MLB_HLS_IV_STRUCT iv_keys[MLB_MAX_IV_COUNT];
int line_pos;
int line_count;
int playlist_size;
char *playlist;
long start_time;
long start_time_offset;
char hls_key_url[MAX_STR_LEN];
char base_url[MAX_STR_LEN];
char base_url_media[MAX_STR_LEN];
int bandwidth;
int last_size;
int seg_time;
struct mlb_hls_master_url *parent;
int priority;
};
typedef struct mlb_hls_stream_url MLB_HLS_STREAM_URL;
struct mlb_hls_master_url
{
MLB_OPT_ARGS *args;
CURL *curl;
CURLcode res;
uint8_t do_loop;
uint32_t b64_decoded_len;
char b64_decoded[MAX_STR_LEN*2];
char base_url[MAX_STR_LEN];
char master_url[MAX_STR_LEN];
uint8_t dec_key[AES128_KEY_SIZE];
char params[MAX_STR_LEN];
long stream_start_time;
int stream_count;
int current_priority;
int max_priority;
int decrypted_size;
int decrypted_count;
int current_seg_line;
int last_key_line;
// int key_line_spacing;
int seg_count;
long seg_ftime;
int seg_fspike;
int seg_fgood;
MLB_HLS_IV_STRUCT *current_iv;
MLB_HLS_STREAM_URL streams[MLB_HLS_MAX_STREAMS];
pthread_t url_thread;
pthread_mutex_t playlist_mutex;
int media_size;
int media_pos;
uint8_t * media_in;
uint8_t * media_out;
pthread_t cmd_thread;
char cmd_params[MAX_STR_LEN];
};
typedef struct mlb_hls_master_url MLB_HLS_MASTER_URL;
struct mlb_url_pass
{
MLB_HLS_MASTER_URL *parent;
MLB_HLS_STREAM_URL *stream;
MLB_HLS_IV_STRUCT *iv;
int write_size;
int write_pos;
uint8_t * write_buf;
};
typedef struct mlb_url_pass MLB_URL_PASS;
void mlb_master_add_stream(MLB_HLS_MASTER_URL *, char *, int);
#endif