shoutcast_output.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. #ifndef __SHOUTCAST_OUTPUT_H__
  2. #define __SHOUTCAST_OUTPUT_H__
  3. #include <time.h>
  4. #include <string>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <list>
  8. #include <fstream>
  9. #include "c_serial_jobmanager.h"
  10. #include "../Components/wac_network/wac_network_connection_api.h"
  11. #include <WinSock2.h>
  12. #include "../Encoders/c_encoder.h"
  13. #include "../Encoders/c_encoder_mp3dll.h"
  14. #include "../lame/include/lame.h"
  15. #include "../lame/libmp3lame/lame_global_flags.h"
  16. #include "../uvAuth21/uvAuth21.h"
  17. #define UV_SYNC_BYTE 0x5A
  18. #define UV_RESERVED 0x00
  19. #define UV_END 0x00
  20. #define UV_END_LEN 1
  21. #define UV_HEADER_LEN 6
  22. #define UV_META_LEN 6
  23. #define UV_FRAME_LEN 16384
  24. #define UV_MAX_DATA_LEN (UV_FRAME_LEN - UV_HEADER_LEN - UV_END_LEN)
  25. #define UV_MAX_META_LEN (UV_FRAME_LEN - UV_HEADER_LEN - UV_META_LEN - UV_END_LEN)
  26. #define UV_MAX_META_FRAGMENTS 32
  27. #define UV_MAX_TOTAL_META_LEN (UV_MAX_META_LEN * UV_MAX_META_FRAGMENTS)
  28. typedef struct {
  29. char* name;
  30. bool parent;
  31. bool children;
  32. } SCgenres;
  33. static SCgenres genres[] = {{"Alternative", true, true},
  34. {"Adult Alternative", false},
  35. {"Britpop", false},
  36. {"Classic Alternative", false},
  37. {"College", false},
  38. {"Dancepunk", false},
  39. {"Dream Pop", false},
  40. {"Emo", false},
  41. {"Goth", false},
  42. {"Grunge", false},
  43. {"Hardcore", false},
  44. {"Indie Pop", false},
  45. {"Indie Rock", false},
  46. {"Industrial", false},
  47. {"LoFi", false},
  48. {"Modern Rock", false},
  49. {"New Wave", false},
  50. {"Noise Pop", false},
  51. {"Post Punk", false},
  52. {"Power Pop", false},
  53. {"Punk", false},
  54. {"Ska", false},
  55. {"Xtreme", false},
  56. {"Blues", true, true},
  57. {"Acoustic Blues", false},
  58. {"Cajun and Zydeco", false},
  59. {"Chicago Blues", false},
  60. {"Contemporary Blues", false},
  61. {"Country Blues", false},
  62. {"Delta Blues", false},
  63. {"Electric Blues", false},
  64. {"Classical", true, true},
  65. {"Baroque", false},
  66. {"Chamber", false},
  67. {"Choral", false},
  68. {"Classical Period", false},
  69. {"Early Classical", false},
  70. {"Impressionist", false},
  71. {"Modern", false},
  72. {"Opera", false},
  73. {"Piano", false},
  74. {"Romantic", false},
  75. {"Symphony", false},
  76. {"Country", true, true},
  77. {"Alt Country", false},
  78. {"Americana", false},
  79. {"Bluegrass", false},
  80. {"Classic Country", false},
  81. {"Contemporary Bluegrass", false},
  82. {"Contemporary Country", false},
  83. {"Honky Tonk", false},
  84. {"Hot Country Hits", false},
  85. {"Western", false},
  86. {"Decades", true, true},
  87. {"30s", false},
  88. {"40s", false},
  89. {"50s", false},
  90. {"60s", false},
  91. {"70s", false},
  92. {"80s", false},
  93. {"90s", false},
  94. {"00s", false},
  95. {"Easy Listening", true, true},
  96. {"Exotica", false},
  97. {"Light Rock", false},
  98. {"Lounge", false},
  99. {"Orchestral Pop", false},
  100. {"Polka", false},
  101. {"Space Age Pop", false},
  102. {"Electronic", true, true},
  103. {"Acid House", false},
  104. {"Ambient", false},
  105. {"Big Beat", false},
  106. {"Breakbeat", false},
  107. {"Dance", false},
  108. {"Demo", false},
  109. {"Disco", false},
  110. {"Downtempo", false},
  111. {"Drum and Bass", false},
  112. {"Dubstep", false},
  113. {"Electro", false},
  114. {"Garage", false},
  115. {"Hard House", false},
  116. {"House", false},
  117. {"IDM", false},
  118. {"Jungle", false},
  119. {"Progressive", false},
  120. {"Techno", false},
  121. {"Trance", false},
  122. {"Tribal", false},
  123. {"Trip Hop", false},
  124. {"Folk", true, true},
  125. {"Alternative Folk", false},
  126. {"Contemporary Folk", false},
  127. {"Folk Rock", false},
  128. {"New Acoustic", false},
  129. {"Old Time", false},
  130. {"Traditional Folk", false},
  131. {"World Folk", false},
  132. {"Inspirational", true, true},
  133. {"Christian", false},
  134. {"Christian Metal", false},
  135. {"Christian Rap", false},
  136. {"Christian Rock", false},
  137. {"Classic Christian", false},
  138. {"Contemporary Gospel", false},
  139. {"Gospel", false},
  140. {"Praise and Worship", false},
  141. {"Sermons and Services", false},
  142. {"Southern Gospel", false},
  143. {"Traditional Gospel", false},
  144. {"International", true, true},
  145. {"African", false},
  146. {"Afrikaans", false},
  147. {"Arabic", false},
  148. {"Asian", false},
  149. {"Bollywood", false},
  150. {"Brazilian", false},
  151. {"Caribbean", false},
  152. {"Celtic", false},
  153. {"Creole", false},
  154. {"European", false},
  155. {"Filipino", false},
  156. {"French", false},
  157. {"German", false},
  158. {"Greek", false},
  159. {"Hawaiian and Pacific", false},
  160. {"Hebrew", false},
  161. {"Hindi", false},
  162. {"Indian", false},
  163. {"Islamic", false},
  164. {"Japanese", false},
  165. {"Klezmer", false},
  166. {"Korean", false},
  167. {"Mediterranean", false},
  168. {"Middle Eastern", false},
  169. {"North American", false},
  170. {"Russian", false},
  171. {"Soca", false},
  172. {"South American", false},
  173. {"Tamil", false},
  174. {"Turkish", false},
  175. {"Worldbeat", false},
  176. {"Zouk", false},
  177. {"Jazz", true, true},
  178. {"Acid Jazz", false},
  179. {"Avant Garde", false},
  180. {"Big Band", false},
  181. {"Bop", false},
  182. {"Classic Jazz", false},
  183. {"Cool Jazz", false},
  184. {"Fusion", false},
  185. {"Hard Bop", false},
  186. {"Latin Jazz", false},
  187. {"Smooth Jazz", false},
  188. {"Swing", false},
  189. {"Vocal Jazz", false},
  190. {"World Fusion", false},
  191. {"Latin", true, true},
  192. {"Bachata", false},
  193. {"Banda", false},
  194. {"Bossa Nova", false},
  195. {"Cumbia", false},
  196. {"Flamenco", false},
  197. {"Latin Dance", false},
  198. {"Latin Pop", false},
  199. {"Latin Rap and Hip Hop", false},
  200. {"Latin Rock", false},
  201. {"Mariachi", false},
  202. {"Merengue", false},
  203. {"Ranchera", false},
  204. {"Reggaeton", false},
  205. {"Regional Mexican", false},
  206. {"Salsa", false},
  207. {"Samba", false},
  208. {"Tango", false},
  209. {"Tejano", false},
  210. {"Tropicalia", false},
  211. {"Metal", true, true},
  212. {"Black Metal", false},
  213. {"Classic Metal", false},
  214. {"Death Metal", false},
  215. {"Extreme Metal", false},
  216. {"Grindcore", false},
  217. {"Hair Metal", false},
  218. {"Heavy Metal", false},
  219. {"Metalcore", false},
  220. {"Power Metal", false},
  221. {"Progressive Metal", false},
  222. {"Rap Metal", false},
  223. {"Thrash Metal", false},
  224. {"Misc", true, false},
  225. {"New Age", true, true},
  226. {"Environmental", false},
  227. {"Ethnic Fusion", false},
  228. {"Healing", false},
  229. {"Meditation", false},
  230. {"Spiritual", false},
  231. {"Pop", true, true},
  232. {"Adult Contemporary", false},
  233. {"Barbershop", false},
  234. {"Bubblegum Pop", false},
  235. {"Dance Pop", false},
  236. {"Idols", false},
  237. {"JPOP", false},
  238. {"KPOP", false},
  239. {"Oldies", false},
  240. {"Soft Rock", false},
  241. {"Teen Pop", false},
  242. {"Top 40", false},
  243. {"World Pop", false},
  244. {"Public Radio", true, true},
  245. {"College", false},
  246. {"News", false},
  247. {"Sports", false},
  248. {"Talk", false},
  249. {"Weather", false},
  250. {"R&B and Urban", true, false},
  251. {"Classic R&B", false},
  252. {"Contemporary R&B", false},
  253. {"Doo Wop", false},
  254. {"Funk", false},
  255. {"Motown", false},
  256. {"Neo Soul", false},
  257. {"Quiet Storm", false},
  258. {"Soul", false},
  259. {"Urban Contemporary", false},
  260. {"Rap", true, true},
  261. {"Alternative Rap", false},
  262. {"Dirty South", false},
  263. {"East Coast Rap", false},
  264. {"Freestyle", false},
  265. {"Gangsta Rap", false},
  266. {"Hip Hop", false},
  267. {"Mixtapes", false},
  268. {"Old School", false},
  269. {"Turntablism", false},
  270. {"Underground Hip Hop", false},
  271. {"West Coast Rap", false},
  272. {"Reggae", true, true},
  273. {"Contemporary Reggae", false},
  274. {"Dancehall", false},
  275. {"Dub", false},
  276. {"Pop Reggae", false},
  277. {"Ragga", false},
  278. {"Reggae Roots", false},
  279. {"Rock Steady", false},
  280. {"Rock", true, true},
  281. {"Adult Album Alternative", false},
  282. {"British Invasion", false},
  283. {"Celtic Rock", false},
  284. {"Classic Rock", false},
  285. {"Garage Rock", false},
  286. {"Glam", false},
  287. {"Hard Rock", false},
  288. {"Jam Bands", false},
  289. {"JROCK", false},
  290. {"Piano Rock", false},
  291. {"Prog Rock", false},
  292. {"Psychedelic", false},
  293. {"Rock & Roll", false},
  294. {"Rockabilly", false},
  295. {"Singer and Songwriter", false},
  296. {"Surf", false},
  297. {"Seasonal and Holiday", true, true},
  298. {"Anniversary", false},
  299. {"Birthday", false},
  300. {"Christmas", false},
  301. {"Halloween", false},
  302. {"Hanukkah", false},
  303. {"Honeymoon", false},
  304. {"Kwanzaa", false},
  305. {"Valentine", false},
  306. {"Wedding", false},
  307. {"Winter", false},
  308. {"Soundtracks", true, true},
  309. {"Anime", false},
  310. {"Kids", false},
  311. {"Original Score", false},
  312. {"Showtunes", false},
  313. {"Video Game Music", false},
  314. {"Talk", true, true},
  315. {"BlogTalk", false},
  316. {"Comedy", false},
  317. {"Community", false},
  318. {"Educational", false},
  319. {"Government", false},
  320. {"News", false},
  321. {"Old Time Radio", false},
  322. {"Other Talk", false},
  323. {"Political", false},
  324. {"Scanner", false},
  325. {"Spoken Word", false},
  326. {"Sports", false},
  327. {"Technology", false},
  328. {"Themes", true, true},
  329. {"Adult", false},
  330. {"Best Of", false},
  331. {"Chill", false},
  332. {"Eclectic", false},
  333. {"Experimental", false},
  334. {"Female", false},
  335. {"Heartache", false},
  336. {"Instrumental", false},
  337. {"LGBT", false},
  338. {"Love and Romance", false},
  339. {"Party Mix", false},
  340. {"Patriotic", false},
  341. {"Rainy Day Mix", false},
  342. {"Reality", false},
  343. {"Sexy", false},
  344. {"Shuffle", false},
  345. {"Travel Mix", false},
  346. {"Tribute", false},
  347. {"Trippy", false},
  348. {"Work Mix", false}
  349. };
  350. // pulled from nmrCommon\intTypes.h
  351. typedef unsigned char __uint8;
  352. typedef unsigned short __uint16;
  353. typedef unsigned int __uint32;
  354. typedef unsigned long long __uint64;
  355. #pragma pack(push,1)
  356. // this structure should be 16384 bytes in total size
  357. // and is defined in full size so that we know its ok
  358. struct uv2xHdr
  359. { // uvox2 message
  360. __uint8 sync;
  361. __uint8 qos;
  362. __uint16 msgType;
  363. __uint16 msgLen;
  364. __uint8 m_data[UV_MAX_DATA_LEN];
  365. __uint8 end;
  366. };
  367. struct uv2xMetadataHdr
  368. { /* uvox 2 metadata header */
  369. __uint8 sync;
  370. __uint8 qos;
  371. __uint16 msgType;
  372. __uint16 msgLen;
  373. __uint16 id; /* ID (cookie) identifying a metadata package */
  374. __uint16 span; /* Span of messages in the metadata package being assembled */
  375. __uint16 index; /* Index of the message in the metadata package being assembled */
  376. __uint8 m_data[UV_MAX_META_LEN];
  377. __uint8 end;
  378. };
  379. #pragma pack(pop)
  380. #define MSG_AUTH 0x1001
  381. #define MSG_BROADCAST_SETUP 0x1002
  382. #define MSG_NEGOTIATE_BUFFER_SIZE 0x1003
  383. #define MSG_STANDBY 0x1004
  384. #define MSG_TERMINATE 0x1005
  385. #define MSG_FLUSH_CACHED_METADATA 0x1006
  386. #define MSG_LISTENER_AUTHENTICATION 0x1007
  387. #define MSG_MAX_PAYLOAD_SIZE 0x1008
  388. #define MSG_CIPHER 0x1009
  389. #define MSG_MIME_TYPE 0x1040
  390. #define MSG_FILE_TRANSFER_BEGIN 0x1050
  391. #define MSG_FILE_TRANSFER_DATA 0x1051
  392. #define MSG_BROADCAST_INTERRUPTION 0x2001
  393. #define MSG_BROADCAST_TERMINATE 0x2002
  394. #define MSG_ICYNAME 0x1100
  395. #define MSG_ICYGENRE 0x1101
  396. #define MSG_ICYURL 0x1102
  397. #define MSG_ICYPUB 0x1103
  398. #define MSG_METADATA_CONTENTINFO 0x3000
  399. #define MSG_METADATA_URL 0x3001
  400. #define MSG_METADATA_XML 0x3901
  401. #define MSG_METADATA_XML_NEW 0x3902
  402. // only id the start of the album art type as it's variable
  403. #define MSG_METADATA_ALBUMART 0x4000
  404. #define MSG_METADATA_STATION_ART 0x0000
  405. #define MSG_METADATA_PLAYING_ART 0x0100
  406. /*
  407. 0x4 0x0xx Station logo
  408. 0x4 0x1xx Album art
  409. 00 = image/jpeg
  410. 01 = image/png
  411. 02 = image/bmp
  412. 03 = image/gif
  413. */
  414. #define MSG_METADATA_TIMEREMAINING 0x5001
  415. #define MP3_DATA 0x7000
  416. #define VLB_DATA 0x8000
  417. #define AAC_LC_DATA 0x8001
  418. #define AACP_DATA 0x8003
  419. #define OGG_DATA 0x8004
  420. struct T_OUTPUT_CONFIG {
  421. char Name[32];
  422. wchar_t DisplayName[32];
  423. char UserID[256];
  424. char Address[1024];
  425. u_short Port;
  426. char StationID[12];
  427. char Password[256]; // 4 - 8 for 1.8.2
  428. char cipherkey[64]; // sc2 cipherkey
  429. int AutoRecon;
  430. int ReconTime;
  431. char Description[1024];
  432. char ServerURL[2048];
  433. char Genre[256];
  434. char ICQ[128];
  435. char AIM[1024];
  436. char IRC[1024];
  437. int Public;
  438. int doTitleUpdate;
  439. int protocol;
  440. int protocol_retry;
  441. char Now[1024];
  442. char Next[1024];
  443. };
  444. #define DEFAULT_ENCODER (C_ENCODER *)(-1)
  445. #define OM_ENCODE 1
  446. #define OM_OUTPUT 2
  447. #define OM_OTHER 4
  448. #define OM_ALL (OM_ENCODE | OM_OUTPUT | OM_OTHER)
  449. enum OUTPUTTYPE {
  450. OUTTYPE_SOURCE,
  451. OUTTYPE_TITLE,
  452. };
  453. typedef unsigned long ARGB32;
  454. struct T_OUTPUT_TITLE {
  455. wchar_t *Title;
  456. wchar_t *Song;
  457. wchar_t *Album;
  458. wchar_t *Artist;
  459. wchar_t *Genre;
  460. wchar_t *Comment;
  461. wchar_t *Year;
  462. std::vector<std::wstring> NextList;
  463. void *APIC[2];
  464. int APICLength[2];
  465. int APICType[2];
  466. T_OUTPUT_TITLE() : Title(0), Song(0), Album(0), Artist(0), Genre(0), Comment(0), Year(0)
  467. {
  468. memset(APIC, 0, sizeof(void *) * 2);
  469. memset(APICLength, 0, sizeof(int) * 2);
  470. memset(APICType, 0, sizeof(int) * 2);
  471. }
  472. ~T_OUTPUT_TITLE()
  473. {
  474. if (Title)
  475. {
  476. free(Title);
  477. Title = 0;
  478. }
  479. if (Song)
  480. {
  481. free(Song);
  482. Song = 0;
  483. }
  484. if (Album)
  485. {
  486. free(Album);
  487. Album = 0;
  488. }
  489. if (Artist)
  490. {
  491. free(Artist);
  492. Artist = 0;
  493. }
  494. if (Genre)
  495. {
  496. free(Genre);
  497. Genre = 0;
  498. }
  499. if (Comment)
  500. {
  501. free(Comment);
  502. Comment = 0;
  503. }
  504. if (Year)
  505. {
  506. free(Year);
  507. Year = 0;
  508. }
  509. }
  510. };
  511. struct T_OUTPUT_INFO {
  512. unsigned int BytesSent; // how many bytes of content we've sent
  513. clock_t ConnectionTime; // time a socket connection occurred
  514. int Version; // server version
  515. int Caps; // server capabilities
  516. int Reconnect; // flag for the reconnection algorithm
  517. int ReconnectTime; // value used in conjunction with the reconnection algorithm
  518. int Succeeded; // had at least one successful connection (for reconnection alg.) -1 = password failure
  519. int last_state; // using this as a means to allow for closing on errors but able to show a better message
  520. int Switching; // if we're doing an automatic protocol version change (from v2 to v1)
  521. char *ErrorMsg;
  522. time_t ConnectedAt;
  523. int meta_cached;
  524. int art_cached[2];
  525. unsigned short art_index[2];
  526. unsigned short art_cached_span[2];
  527. int art_cached_length[2];
  528. // metadata information about the stream, etc
  529. wchar_t *Title;
  530. std::vector<std::wstring> NextList;
  531. wchar_t *Song;
  532. wchar_t *Album;
  533. wchar_t *Artist;
  534. wchar_t *Genre;
  535. wchar_t *Comment;
  536. wchar_t *Year;
  537. void *APIC[2];
  538. int APICLength[2];
  539. int APICType[2];
  540. T_OUTPUT_INFO() : BytesSent(0), ConnectionTime(0), Version(0),
  541. Caps(0), Reconnect(0), ReconnectTime(0),
  542. Succeeded(0), last_state(0), Switching(0),
  543. ErrorMsg(0), ConnectedAt(0), meta_cached(0),
  544. Title(0), Song(0), Album(0), Artist(0),
  545. Genre(0), Comment(0), Year(0)
  546. {
  547. memset(art_cached, 0, sizeof(int) * 2);
  548. memset(art_index, 0, sizeof(unsigned short) * 2);
  549. memset(art_cached_span, 0, sizeof(unsigned short) * 2);
  550. memset(art_cached_length, 0, sizeof(int) * 2);
  551. memset(APIC, 0, sizeof(void *) * 2);
  552. memset(APICLength, 0, sizeof(int) * 2);
  553. memset(APICType, 0, sizeof(int) * 2);
  554. }
  555. ~T_OUTPUT_INFO()
  556. {
  557. if (Title)
  558. {
  559. free(Title);
  560. Title = 0;
  561. }
  562. if (Song)
  563. {
  564. free(Song);
  565. Song = 0;
  566. }
  567. if (Album)
  568. {
  569. free(Album);
  570. Album = 0;
  571. }
  572. if (Artist)
  573. {
  574. free(Artist);
  575. Artist = 0;
  576. }
  577. if (Genre)
  578. {
  579. free(Genre);
  580. Genre = 0;
  581. }
  582. if (Comment)
  583. {
  584. free(Comment);
  585. Comment = 0;
  586. }
  587. if (Year)
  588. {
  589. free(Year);
  590. Year = 0;
  591. }
  592. if (Succeeded == -2 && ErrorMsg) {
  593. free(ErrorMsg);
  594. ErrorMsg = 0;
  595. }
  596. }
  597. };
  598. struct T_OUTPUT {
  599. int Connection; // using this for the title update callback so the correct instance is updated
  600. void (*TitleCallback)(const int Connection, const int Mode);
  601. api_connection *Output;
  602. enum OUTPUTTYPE Type;
  603. int Bitrate; // this shouldn't be here, but it's the only way we can tell the shoutcast server the bitrate
  604. char *ContentType; // neither should this
  605. int SlowClose; // set to 1 to wait until all data is sent before closing the connection
  606. T_OUTPUT_CONFIG *Config;
  607. T_OUTPUT_INFO Info;
  608. T_OUTPUT() : Connection(0), TitleCallback(0), Output(0), Type(OUTTYPE_SOURCE), Bitrate(0), ContentType(0), SlowClose(0), Config(0) {}
  609. };
  610. enum OUTPUTSTATE {
  611. OUT_ERROR, // not a true state, but is returned when GetState() is called with an invalid connection handle
  612. OUT_DISCONNECTED,
  613. OUT_CONNECT,
  614. OUT_REQUEST_CIPHER,
  615. OUT_RECV_CIPHER,
  616. OUT_SENDAUTH,
  617. OUT_RECVAUTHRESPONSE,
  618. OUT_SEND_MIME,
  619. OUT_RECV_MIME,
  620. OUT_SEND_BITRATE,
  621. OUT_RECV_BITRATE,
  622. OUT_SEND_BUFSIZE,
  623. OUT_RECV_BUFSIZE,
  624. OUT_SEND_MAX,
  625. OUT_RECV_MAX,
  626. OUT_SENDYP,
  627. OUT_SEND_INITFLUSH,
  628. OUT_RECV_INITFLUSH,
  629. OUT_SEND_INITSTANDBY,
  630. OUT_RECV_INITSTANDBY,
  631. /*OUT_SEND_INTRO,
  632. OUT_RECV_INTRO,
  633. OUT_SEND_BACKUP,
  634. OUT_RECV_BACKUP,*/
  635. OUT_SENDCONTENT,
  636. OUT_DISCONNECT,
  637. OUT_RECONNECT,
  638. OUT_TITLESENDUPDATE,
  639. OUT_FAIL_CIPHER,
  640. OUT_SEND_METADATA,
  641. OUT_SEND_ARTWORK,
  642. };
  643. static void *mutex;
  644. class SHOUTCAST_OUTPUT {
  645. private:
  646. C_ENCODER *Encoder;
  647. int IOwnEncoder;
  648. C_SERIAL_JOBMANAGER<T_OUTPUT> OutputManager;
  649. T_OUTPUT_TITLE metadata;
  650. protected:
  651. static int Output_Disconnected(int state, int last_state, T_OUTPUT *userData);
  652. static int Output_Connect(int state, int last_state, T_OUTPUT *userData);
  653. static int Output_Request_Cipher(int state, int last_state, T_OUTPUT *userData);
  654. static int Output_Receive_Cipher(int state, int last_state, T_OUTPUT *userData);
  655. static int Output_SendAuth(int state, int last_state, T_OUTPUT *userData);
  656. static int Output_RecvAuthResponse(int state, int last_state, T_OUTPUT *userData);
  657. static int Output_Send_Mime(int state, int last_state, T_OUTPUT *userData);
  658. static int Output_Recv_Mime(int state, int last_state, T_OUTPUT *userData);
  659. static int Output_Send_Bitrate(int state, int last_state, T_OUTPUT *userData);
  660. static int Output_Recv_Bitrate(int state, int last_state, T_OUTPUT *userData);
  661. static int Output_Send_Buf_Size(int state, int last_state, T_OUTPUT *userData);
  662. static int Output_Recv_Buf_Size(int state, int last_state, T_OUTPUT *userData);
  663. static int Output_Send_Max_Size(int state, int last_state, T_OUTPUT *userData);
  664. static int Output_Recv_Max_Size(int state, int last_state, T_OUTPUT *userData);
  665. static int Output_DUMMY(int state, int last_state, T_OUTPUT *userData);
  666. static int Output_SendYP(int state, int last_state, T_OUTPUT *userData);
  667. static int Output_Send_InitFlush(int state, int last_state, T_OUTPUT *userData);
  668. static int Output_Recv_InitFlush(int state, int last_state, T_OUTPUT *userData);
  669. static int Output_Send_InitStandby(int state, int last_state, T_OUTPUT *userData);
  670. static int Output_Recv_InitStandby(int state, int last_state, T_OUTPUT *userData);
  671. /*static int Output_Send_Intro(int state, int last_state, T_OUTPUT *userData);
  672. static int Output_Recv_Intro(int state, int last_state, T_OUTPUT *userData);
  673. static int Output_Send_Backup(int state, int last_state, T_OUTPUT *userData);
  674. static int Output_Recv_Backup(int state, int last_state, T_OUTPUT *userData);*/
  675. static int Output_SendContent(int state, int last_state, T_OUTPUT *userData);
  676. static int Output_Disconnect(int state, int last_state, T_OUTPUT *userData);
  677. static int Output_Reconnect(int state, int last_state, T_OUTPUT *userData);
  678. static int Output_Title_SendUpdate(int state, int last_state, T_OUTPUT *userData);
  679. static int Output_Send_Metadata(int state, int last_state, T_OUTPUT *userData);
  680. static int Output_Send_Artwork(int state, int last_state, T_OUTPUT *userData);
  681. // uvox21
  682. static void createUvoxFrame(int length, char *payload_in, int type, T_OUTPUT *userData);
  683. static int createUvoxMetaFrame(int length, char *payload_in, int type,
  684. T_OUTPUT *userData, unsigned short id, unsigned short span = 1);
  685. static int parseUvoxFrame(char *payload_in, char *payload_out);
  686. static int checkUvoxFrameForError(char *pload_out, int state, T_OUTPUT *userData);
  687. void (*lame_init)(void);
  688. void (*lame_init_params)(lame_global_flags *);
  689. int (*lame_encode_buffer_interleaved)(lame_global_flags *, short int pcm[], int num_samples, char *mp3buffer, int mp3buffer_size);
  690. int (*lame_encode_flush)(lame_global_flags *, char *mp3buffer, int size);
  691. HINSTANCE libinst;
  692. public:
  693. SHOUTCAST_OUTPUT();
  694. void SetLame(void *init, void *params, void *encode, void *finish);
  695. ~SHOUTCAST_OUTPUT();
  696. int Run(int mode = 0, void *Input = NULL, int InputSize = 0, int SaveEncoder = -1);
  697. int AddOutput(int Connection, T_OUTPUT_CONFIG *Config, void (*TitleCallback)(const int Connection, const int Mode)=0);
  698. void UpdateOutput(int Connection);
  699. void RemoveOutput(int Connection);
  700. int ConnectOutput(int Connection);
  701. int DisconnectOutput(int Connection, int withReconnect = 0, int reconnectTime = -1); // withReconnect of -1 will use the output config's setting
  702. void SetEncoder(C_ENCODER *encoder, int takeOwnership = 0);
  703. // we will attempt to cache the title information to save on duplication and
  704. // also to make it easier for the title to be re-sent on server disconnect
  705. void UpdateTitleCache(wchar_t *Title, std::vector<std::wstring> NextList, wchar_t *Song,
  706. wchar_t *Album, wchar_t *Artist, wchar_t *Genre, wchar_t *Comment,
  707. wchar_t* Year, int Connection, bool sendNext);
  708. void UpdateTitle(wchar_t *Title, std::vector<std::wstring> NextList,
  709. int Connection, bool sendNext, bool UseCache = true);
  710. void UpdateArtwork(int Connection);
  711. void UpdateAlbumArtCache(void* APIC, int APIClength, int APICType, int Connection);
  712. int UpdateAlbumArt(int Connection);
  713. enum OUTPUTSTATE GetState(int Connection);
  714. T_OUTPUT_CONFIG *operator[](int Connection);
  715. T_OUTPUT_CONFIG *GetOutput(int Connection);
  716. C_ENCODER *GetEncoder();
  717. T_OUTPUT_INFO *GetOutputInfo(int Connection);
  718. };
  719. static unsigned short mid = 1;
  720. #ifdef _DEBUG
  721. #define DEBUG_STATE OutputDebugString(__FUNCTION__); OutputDebugString("\r\n");
  722. #else
  723. #define DEBUG_STATE
  724. #endif
  725. #define STATE userData->Info.last_state = last_state
  726. #define LOCK if(WaitForSingleObject(mutex,INFINITE) == WAIT_OBJECT_0)
  727. #define UNLOCK ReleaseMutex(mutex);
  728. extern char sourceVersion[64];
  729. extern HWND hMainDLG;
  730. #endif // !__SHOUTCAST_OUTPUT_H__