Je ne trouve pas la manière de lire à partir de la RAM (buffer), ça m'aurait simplifié la vie...
Voilà où j'en suis:
J'ai réussi à faire un environnement console provisoire (limité à Windows) pour lire un buffer de 64kb de la radio en boucle.
Ce code me servira juste à tester les différentes fonctions de mss....
Quand j'aurais trouvé des manières d'optimiser et de rendre ce code fonctionnel (pour lire la radio en continu), il me restera encore tout le travail de l'adapter à metin...
// MilesSysTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
#include <WinInet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HTTP_USER_AGENT "httprip"
#define BUFFER_SIZE 64000
using namespace std;
void usage(void);
int InternetSaveFile(const char *, const char *);
HSTREAM openFile(const char *);
void playRadio(HSTREAM);
HDIGDRIVER ms_DIGDriver = NULL;
int _tmain(int argc, _TCHAR* argv[])
{
FILE *input = NULL;
char buffer[BUFFER_SIZE] = { 0 };
const char url[] = "[Hidden Content]";
AIL_set_redist_directory("miles");
AIL_startup();
// Initialize MSS
ms_DIGDriver = AIL_open_digital_driver(44100, 16, 2, 0);
// Play Sound of pointer
InternetSaveFile(url, "tmp.mp3");
//playRadio(hStream);
return 0;
}
int InternetSaveFile(const char *requesturl, const char *outputfile)
{
const char http[] = "HTTP";
HANDLE file;
SECURITY_ATTRIBUTES sa;
HINTERNET internet;
HINTERNET url;
char *buf = NULL;
DWORD bytesread;
DWORD byteswritten;
int k;
// validate protocol -- first 4 alphas should be http, case insensitive
for (k = 0; k < 4; k++)
if (requesturl[k] != http[k] && requesturl[k] != (char)(http[k] + 32))
return 0;
file = CreateFile(outputfile,
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (file == INVALID_HANDLE_VALUE)
return 0;
internet = InternetOpen(HTTP_USER_AGENT,
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0);
if (internet == NULL)
return 0;
url = InternetOpenUrl(internet,
requesturl,
NULL,
0,
INTERNET_FLAG_PRAGMA_NOCACHE,
0);
if (url == NULL)
return 0;
buf = (char *)malloc(BUFFER_SIZE + 1);
if (buf == NULL)
return 0;
if (InternetReadFile(url,
buf,
BUFFER_SIZE,
&bytesread))
{
//if (bytesread == 0) break;
WriteFile(file,
buf,
bytesread,
&byteswritten,
NULL);
}
free(buf);
InternetCloseHandle(url);
InternetCloseHandle(internet);
CloseHandle(file);
HSTREAM hStream = AIL_open_stream(ms_DIGDriver, "tmp.mp3", 0);
if (hStream == NULL)
{
printf("Null Pointer buf: %d", bytesread);
//break;
}
playRadio(hStream);
return 1;
}
void playRadio(HSTREAM hStream)
{
printf("Pointer: %p", hStream);
AIL_set_stream_volume_levels(hStream, 1.0f, 1.0f);
AIL_set_stream_loop_count(hStream, 0);
AIL_start_stream(hStream);
while (AIL_stream_status(hStream) != -1)
{
continue;
Sleep(20);
}
}