chainedstream_parse.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <ogg/ogg.h>
  5. #include <vorbis/vorbisfile.h>
  6. static size_t callback_fread(void *ptr, size_t size, size_t nmemb, HANDLE hFile)
  7. {
  8. DWORD bw = 0;
  9. ReadFile(hFile,ptr,(DWORD)(size*nmemb),&bw,0);
  10. return bw/size;
  11. }
  12. static size_t callback_write(void * ptr, size_t size, size_t nmemb, HANDLE hFile)
  13. {
  14. DWORD bw = 0;
  15. WriteFile(hFile,ptr,(DWORD)(size*nmemb),&bw,0);
  16. return bw/size;
  17. }
  18. static int callback_fseek(HANDLE hFile, __int64 offset, int whence)
  19. {
  20. __int64 temp = offset;
  21. SetFilePointer(hFile,*(DWORD*)&temp,((long*)&temp+1),whence);
  22. return 0;
  23. }
  24. static int callback_fclose(HANDLE f)
  25. {
  26. return 0;
  27. }
  28. static __int64 callback_ftell(HANDLE hFile)
  29. {
  30. __int64 ret=0;
  31. *(DWORD*)&ret = SetFilePointer(hFile,0,((long*)&ret+1),FILE_CURRENT);
  32. return ret;
  33. }
  34. static void* callbacks[4]=
  35. {
  36. callback_fread,callback_fseek,callback_fclose,callback_ftell
  37. };
  38. namespace ogg_helper
  39. {
  40. int num_get_tracks(HANDLE hFile/*track_indexer::callback * out,reader * r*/)
  41. {
  42. SetFilePointer(hFile,0,0,FILE_BEGIN);
  43. OggVorbis_File l_vf;
  44. memset(&l_vf,0,sizeof(l_vf));
  45. if (ov_open_callbacks(hFile,&l_vf,0,0,*(ov_callbacks*)callbacks))
  46. {
  47. return 0;
  48. }
  49. int rv = l_vf.links;
  50. ov_clear(&l_vf);
  51. return rv;
  52. }
  53. int query_chained_stream_offset(HANDLE hFile,int idx,__int64 * out_beginning,__int64 * out_end)
  54. {
  55. SetFilePointer(hFile,0,0,FILE_BEGIN);
  56. OggVorbis_File l_vf;
  57. memset(&l_vf,0,sizeof(l_vf));
  58. if (ov_open_callbacks(hFile,&l_vf,0,0,*(ov_callbacks*)callbacks))
  59. {
  60. return 0;
  61. }
  62. int retval = 0;
  63. if (idx>=0 && idx<l_vf.links)
  64. {
  65. retval = 1;
  66. *out_beginning = l_vf.offsets[idx];
  67. *out_end = l_vf.offsets[idx+1];
  68. }
  69. ov_clear(&l_vf);
  70. return retval;
  71. }
  72. }