1
0

mp4.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "main.h"
  2. #include "mpeg4audio.h"
  3. #include "api__in_mp4.h"
  4. #include <api/service/waservicefactory.h>
  5. #include <api/service/services.h>
  6. //#include "JPEGDecoder.h"
  7. //#include "MPEG4VideoDecoder.h"
  8. //#include "AVCDecoder.h"
  9. #include "../nu/bitbuffer.h"
  10. #include <assert.h>
  11. void ConfigureDecoderASC(MP4FileHandle file, MP4TrackId track, MP4AudioDecoder *decoder)
  12. {
  13. unsigned char *buffer = NULL;
  14. unsigned __int32 buffer_size = 0;
  15. // TODO: HUGE hack
  16. const char *location = decoder->GetCodecInfoString();
  17. if (location)
  18. MP4GetTrackBytesProperty(file, track, location , (unsigned __int8 **)&buffer, &buffer_size);
  19. else
  20. MP4GetTrackESConfiguration(file, track, (unsigned __int8 **)&buffer, &buffer_size);
  21. if (buffer)
  22. {
  23. decoder->AudioSpecificConfiguration(buffer, buffer_size);
  24. MP4Free(buffer);
  25. }
  26. }
  27. bool CreateDecoder(MP4FileHandle file, MP4TrackId track, MP4AudioDecoder *&decoder, waServiceFactory *&serviceFactory)
  28. {
  29. const char *media_data_name = MP4GetTrackMediaDataName(file, track);
  30. u_int8_t audioType = MP4GetTrackEsdsObjectTypeId(file, track);
  31. u_int8_t mpeg4Type = MP4GetTrackAudioMpeg4Type(file, track);
  32. if (!media_data_name)
  33. media_data_name = "mp4a"; // let's assume it's AAC if nothing else is said
  34. waServiceFactory *sf = 0;
  35. int n = 0;
  36. while (sf = mod.service->service_enumService(WaSvc::MP4AUDIODECODER, n++))
  37. {
  38. MP4AudioDecoder * dec = static_cast<MP4AudioDecoder *>(sf->getInterface());
  39. if (dec && dec->CanHandleCodec(media_data_name)
  40. && (!audioType || dec->CanHandleType(audioType))
  41. && (!mpeg4Type || dec->CanHandleMPEG4Type(mpeg4Type))
  42. /*&& dec->Open() == MP4_SUCCESS*/)
  43. {
  44. //ConfigureDecoderASC(file, track, dec);
  45. decoder = dec;
  46. serviceFactory = sf;
  47. return true;
  48. }
  49. sf->releaseInterface(dec);
  50. }
  51. return false;
  52. }
  53. bool CreateVideoDecoder(MP4FileHandle file, MP4TrackId track, MP4VideoDecoder *&decoder, waServiceFactory *&serviceFactory)
  54. {
  55. const char *media_data_name = MP4GetTrackMediaDataName(file, track);
  56. // TODO check this is ok to disable...
  57. //u_int8_t audioType = MP4GetTrackEsdsObjectTypeId(file, track);
  58. //u_int8_t profileLevel = MP4GetVideoProfileLevel(file, track);
  59. if (!media_data_name)
  60. return false;
  61. waServiceFactory *sf = 0;
  62. int n = 0;
  63. while (sf = mod.service->service_enumService(WaSvc::MP4VIDEODECODER, n++))
  64. {
  65. MP4VideoDecoder *dec = static_cast<MP4VideoDecoder *>(sf->getInterface());
  66. if (dec && dec->CanHandleCodec(media_data_name)
  67. /*&& dec->Open() == MP4_SUCCESS*/)
  68. {
  69. decoder = dec;
  70. serviceFactory = sf;
  71. return true;
  72. }
  73. sf->releaseInterface(dec);
  74. }
  75. /*
  76. if (!strcmp(media_data_name, "mp4v"))
  77. {
  78. // TODO: write a way to get the binary data out of an atom
  79. uint8_t *buffer;
  80. uint32_t buffer_size = 0;
  81. MP4GetTrackESConfiguration(file, track, &buffer, &buffer_size);
  82. decoder = new MPEG4VideoDecoder(0,0);//buffer, buffer_size);
  83. return true;
  84. }
  85. */
  86. return false;
  87. }