Revision 64144d8f

View differences:

chunk_puller.c
1 1
#include <platform.h>
2 2
#include <microhttpd.h>
3 3

  
4
#include <http_default_urls.h>
5 4

  
6
struct connection_info_struct {
5
static struct connection_info_struct {
7 6
  uint8_t *block;
8 7
  int block_size;
9 8
};
9
static int listen_port = 0;
10
static char listen_path[256];
10 11

  
11 12
void request_completed(void *cls, struct MHD_Connection *connection,
12 13
                       void **con_cls, enum MHD_RequestTerminationCode toe) {
......
57 58
  }
58 59

  
59 60
  if(0 == strcmp(method, "POST")) {
60
    if(0 == strcmp(url, UL_DEFAULT_EXTERNALPLAYER_PATH)) {
61
    if(0 == strcmp(url, listen_path)) {
61 62
      con_info = (struct connection_info_struct *)*con_cls;
62 63
      if(*upload_data_size > 0) {
63 64
        block = (uint8_t *)malloc(con_info->block_size+*upload_data_size);
......
87 88
}
88 89

  
89 90

  
90
struct MHD_Daemon *initChunkPuller() {
91
  return MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, UL_DEFAULT_EXTERNALPLAYER_PORT,
91
struct MHD_Daemon *initChunkPuller(const char *path, const int port) {
92
  sprintf(listen_path, "%s", path);
93
  listen_port = port;
94
printf("starting HTTPD on %s port %d\n", listen_path, listen_port);
95
  return MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, listen_port,
92 96
                          NULL, NULL,
93 97
                          &answer_to_connection, NULL, MHD_OPTION_END);
94 98
}
chunk_pusher.c
21 21
	//we need to pack 5 int32s + 2 timeval structs + 1 double
22 22
	static size_t ExternalChunk_header_size = 5*CHUNK_TRANSCODING_INT_SIZE + 2*CHUNK_TRANSCODING_INT_SIZE + 2*CHUNK_TRANSCODING_INT_SIZE + 1*CHUNK_TRANSCODING_INT_SIZE*2;
23 23
	
24
	//update the chunk len
24
	//update the chunk len here because here we know the external chunk header size
25 25
	echunk->len = echunk->payload_len + ExternalChunk_header_size;
26 26

  
27 27
	/* first pack the chunk info that we get from the streamer into an "attributes" block of a regular GRAPES chunk */
......
54 54
		gchunk.data = echunk->data;
55 55

  
56 56
#ifdef NHIO
57
			write_chunk(&gchunk);
57
		write_chunk(&gchunk);
58 58
#else
59
			ret = sendViaCurl(gchunk, ExternalChunk_header_size, echunk, url);
59
		/* 20 bytes are needed to put the chunk header info on the wire + attributes size + payload */
60
		ret = sendViaCurl(gchunk, GRAPES_ENCODED_CHUNK_HEADER_SIZE + gchunk.attributes_size + gchunk.size, url);
60 61
#endif
61 62

  
62 63
		free(grapes_chunk_attributes_block);
chunk_pusher_curl.c
1 1
#include <curl/curl.h>
2 2

  
3
#include "external_chunk_transcoding.h"
3
#include <chunk.h>
4

  
4 5
#include "chunker_streamer.h"
5 6

  
6 7

  
7 8
void initChunkPusher();
8 9
void finalizeChunkPusher();
9
int sendViaCurl(Chunk gchunk, size_t attr_size, ExternalChunk *echunk, char *url);
10
int sendViaCurl(Chunk gchunk, int buffer_size, char *url);
10 11

  
11 12

  
12 13
void initChunkPusher() {	
......
18 19
	curl_global_cleanup();
19 20
}
20 21

  
21

  
22
int sendViaCurl(Chunk gchunk, size_t attr_size, ExternalChunk *echunk, char *url) {
22
int sendViaCurl(Chunk gchunk, int buffer_size, char *url) {
23 23
	//MAKE THE CURL EASY HANDLE GLOBAL? TO REUSE IT?
24 24
	CURL *curl_handle;
25 25
	struct curl_slist *headers=NULL;
26 26
	uint8_t *buffer=NULL;
27
	size_t buffer_size = 0;
27

  
28 28
	int ret = STREAMER_FAIL_RETURN;
29 29

  
30
	/* 20 bytes are needed to put the chunk header info on the wire */
31
	buffer_size = GRAPES_ENCODED_CHUNK_HEADER_SIZE + attr_size + echunk->payload_len;
32 30
	if( (buffer = malloc(buffer_size)) != NULL) {
33 31
		/* encode the GRAPES chunk into network bytes */
34 32
		encodeChunk(&gchunk, buffer, buffer_size);
chunker_player.c
32 32
#include <platform.h>
33 33
#include <microhttpd.h>
34 34

  
35
#include <http_default_urls.h>
35 36
#include "chunker_player.h"
36 37
#include "codec_definitions.h"
37 38

  
......
1070 1071
	SDL_PauseAudio(0);
1071 1072
	video_thread = SDL_CreateThread(video_callback,tval);
1072 1073

  
1073
	//this thread fetches chunks from the network
1074
	daemon = initChunkPuller();
1074
	//this thread fetches chunks from the network by listening to the following path, port
1075
	daemon = initChunkPuller(UL_DEFAULT_EXTERNALPLAYER_PATH, UL_DEFAULT_EXTERNALPLAYER_PORT);
1075 1076

  
1076 1077
	// Wait for user input
1077 1078
	while(!quit) {

Also available in: Unified diff