2007-03-02 01:36:52 +00:00
|
|
|
//
|
|
|
|
// HTTPSource.h
|
|
|
|
// HTTPSource
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 3/1/07.
|
|
|
|
// Copyright 2007 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#import "Plugin.h"
|
|
|
|
|
2022-02-09 21:41:01 +00:00
|
|
|
#include <curl/curl.h>
|
2009-03-07 09:25:13 +00:00
|
|
|
|
2022-02-09 21:41:01 +00:00
|
|
|
#define BUFFER_SIZE 0x10000
|
|
|
|
#define BUFFER_MASK 0xffff
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-02-09 21:41:01 +00:00
|
|
|
#define MAX_METADATA 1024
|
|
|
|
|
|
|
|
#define TIMEOUT 10 // in seconds
|
|
|
|
|
|
|
|
enum {
|
|
|
|
STATUS_UNSTARTED = 0,
|
|
|
|
STATUS_INITIAL = 1,
|
|
|
|
STATUS_READING = 2,
|
|
|
|
STATUS_FINISHED = 3,
|
|
|
|
STATUS_ABORTED = 4,
|
|
|
|
STATUS_SEEK = 5,
|
|
|
|
};
|
|
|
|
|
|
|
|
@interface HTTPSource : NSObject <CogSource> {
|
2022-02-07 05:49:27 +00:00
|
|
|
NSURL *URL;
|
|
|
|
|
2022-02-09 21:41:01 +00:00
|
|
|
int64_t pos; // position in stream; use "& BUFFER_MASK" to make it index into ringbuffer
|
|
|
|
int64_t length;
|
|
|
|
int32_t remaining; // remaining bytes in buffer read from stream
|
|
|
|
int64_t skipbytes;
|
|
|
|
uint8_t buffer[BUFFER_SIZE];
|
|
|
|
|
|
|
|
NSLock *mutex;
|
|
|
|
|
|
|
|
uint8_t nheaderpackets;
|
|
|
|
NSString *content_type;
|
|
|
|
CURL *curl;
|
|
|
|
struct timeval last_read_time;
|
|
|
|
uint8_t status;
|
|
|
|
int icy_metaint;
|
|
|
|
int wait_meta;
|
|
|
|
|
|
|
|
char metadata[MAX_METADATA];
|
|
|
|
size_t metadata_size; // size of metadata in stream
|
|
|
|
size_t metadata_have_size; // amount which is already in metadata buffer
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-02-09 21:41:01 +00:00
|
|
|
char http_err[CURL_ERROR_SIZE];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-02-09 21:41:01 +00:00
|
|
|
BOOL need_abort;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-02-09 21:41:01 +00:00
|
|
|
NSString *album;
|
|
|
|
NSString *artist;
|
|
|
|
NSString *title;
|
|
|
|
NSString *genre;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-02-09 21:41:01 +00:00
|
|
|
// flags (bitfields to save some space)
|
|
|
|
unsigned seektoend : 1; // indicates that next tell must return length
|
|
|
|
unsigned gotheader : 1; // tells that all headers (including ICY) were processed (to start reading body)
|
|
|
|
unsigned icyheader : 1; // tells that we're currently reading ICY headers
|
|
|
|
unsigned gotsomeheader : 1; // tells that we got some headers before body started
|
|
|
|
unsigned gotmetadata : 1; // got some metadata
|
2007-03-02 01:36:52 +00:00
|
|
|
}
|
|
|
|
|
2022-02-09 21:41:01 +00:00
|
|
|
- (BOOL)hasMetadata;
|
|
|
|
- (NSDictionary *)metadata;
|
2007-03-02 01:36:52 +00:00
|
|
|
@end
|