World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
MediaPlayer.cpp
См. документацию.
1 #include "Media/MediaPlayer.h"
2 
3 #include <algorithm>
4 #include <cassert>
5 #include <chrono>
6 #include <deque>
7 #include <map>
8 #include <memory>
9 #include <queue>
10 #include <vector>
11 
14 
15 #include "Engine/Engine.h"
16 #include "Engine/ErrorHandling.h"
18 #include "Engine/Log.h"
19 
20 #include "GUI/GUIWindow.h"
21 #include "IO/Mouse.h"
22 #include "Platform/Api.h"
23 
24 extern "C" {
25 #include "libavcodec/avcodec.h"
26 #include "libavformat/avformat.h"
27 #include "libavutil/avutil.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/opt.h"
32 #include "libswscale/swscale.h"
33 }
34 
35 #pragma comment(lib, "avcodec.lib")
36 #pragma comment(lib, "avformat.lib")
37 #pragma comment(lib, "avutil.lib")
38 #pragma comment(lib, "swscale.lib")
39 #pragma comment(lib, "swresample.lib")
40 
42 
43 MPlayer *pMediaPlayer = nullptr;
45 
47  public:
50  stream_idx = -1;
51  stream = nullptr;
52  dec = nullptr;
53  dec_ctx = nullptr;
54  }
55 
56  virtual ~AVStreamWrapper() {
57  close();
58  }
59 
60  virtual void reset() {
61  if (dec_ctx != nullptr) {
63  }
64  }
65 
66  virtual void close() {
68  stream_idx = -1;
69  stream = nullptr;
70  dec = nullptr;
71  if (dec_ctx != nullptr) {
72  // Close the codec
74  logger->Warning(L"close decoder context file\n");
75  dec_ctx = nullptr;
76  }
77  }
78 
79  virtual bool open(AVFormatContext *format_ctx) = 0;
80 
81  virtual bool open(AVFormatContext *format_ctx, AVMediaType type_) {
82  stream_idx = av_find_best_stream(format_ctx, type_, -1, -1, &dec, 0);
83  if (stream_idx < 0) {
84  close();
85  fprintf(stderr, "ffmpeg: Unable to find audio stream\n");
86  return false;
87  }
88 
89  stream = format_ctx->streams[stream_idx];
91  if (dec_ctx == nullptr) {
92  close();
93  return false;
94  }
95 
96  if (avcodec_parameters_to_context(dec_ctx, stream->codecpar) < 0) {
97  close();
98  return false;
99  }
100  if (avcodec_open2(dec_ctx, dec, nullptr) < 0) {
101  close();
102  return false;
103  }
104 
105  return true;
106  }
107 
113  std::queue<PMemBuffer, std::deque<PMemBuffer>> queue;
114 };
115 
117  public:
119 
120  virtual bool open(AVFormatContext *format_ctx) {
121  if (!AVStreamWrapper::open(format_ctx, AVMEDIA_TYPE_AUDIO)) {
122  return false;
123  }
124 
126  converter, AV_CH_LAYOUT_STEREO, AV_SAMPLE_FMT_S16,
128  dec_ctx->sample_rate, 0, nullptr);
129  if (swr_init(converter) < 0) {
130  logger->Warning(L"swr_init: failed");
132  converter = nullptr;
133  return false;
134  }
135 
136  return true;
137  }
138 
141  AVFrame *frame = av_frame_alloc();
142 
143  if (!queue.empty()) {
144  result = queue.front();
145  queue.pop();
146  }
147 
148  if (avcodec_send_packet(dec_ctx, avpacket) >= 0) {
149  int res = 0;
150  while (res >= 0) {
152  if (res == AVERROR(EAGAIN) || res == AVERROR_EOF) {
153  break;
154  }
155  if (res < 0) {
156  av_frame_free(&frame);
157  return result;
158  }
159  PMemBuffer tmp_buf = AllocMemBuffer(
160  frame->nb_samples * 2 * 2);
161  uint8_t *dst_channels[8] = { 0 };
162  dst_channels[0] = (uint8_t*)tmp_buf->GetData();
163  int got_samples = swr_convert(
164  converter, dst_channels, frame->nb_samples,
165  (const uint8_t**)frame->data, frame->nb_samples);
166  if (got_samples > 0) {
167  if (!result) {
168  result = tmp_buf;
169  } else {
170  queue.push(tmp_buf);
171  }
172  }
173  }
174  }
175 
176  av_frame_free(&frame);
177 
178  return result;
179  }
180 
181  protected:
183 };
184 
186  public:
188  frame_len = 0.;
189  frames_per_second = 0.;
190  converter = nullptr;
191  }
192 
193  virtual bool open(AVFormatContext *format_ctx) {
194  if (!AVStreamWrapper::open(format_ctx, AVMEDIA_TYPE_VIDEO)) {
195  return false;
196  }
197 
198  width = dec_ctx->width;
199  height = dec_ctx->height;
200 
201  frame_len = av_q2d(stream->time_base) * 1000.;
202  frames_per_second = 1. / av_q2d(stream->time_base);
203 
206  AV_PIX_FMT_RGB32, SWS_BICUBIC, nullptr, nullptr, nullptr);
207 
208  return true;
209  }
210 
213  AVFrame *frame = av_frame_alloc();
214 
215  if (!queue.empty()) {
216  result = queue.front();
217  queue.pop();
218  }
219 
220  if (avcodec_send_packet(dec_ctx, avpacket) >= 0) {
221  int res = 0;
222  while (res >= 0) {
224  if (res == AVERROR(EAGAIN) || res == AVERROR_EOF) {
225  break;
226  }
227  if (res < 0) {
228  av_frame_free(&frame);
229  return result;
230  }
231  int linesizes[4] = { 0, 0, 0, 0 };
232  if (av_image_fill_linesizes(linesizes, AV_PIX_FMT_RGB32, width) < 0) {
233  assert(false);
234  }
235  uint8_t *data[4] = { nullptr, nullptr, nullptr, nullptr };
236  PMemBuffer tmp_buf = AllocMemBuffer(frame->height * linesizes[0] * 2);
237  data[0] = (uint8_t*)tmp_buf->GetData();
238 
239  if (sws_scale(converter, frame->data, frame->linesize, 0, frame->height,
240  data, linesizes) < 0) {
241  assert(false);
242  }
243 
244  if (!result) {
245  result = tmp_buf;
246  } else {
247  queue.push(tmp_buf);
248  }
249  }
250  }
251 
252  av_frame_free(&frame);
253 
254  last_frame = result;
255 
256  return result;
257  }
258 
261  double frame_len;
262  SwsContext *converter;
263  int width;
264  int height;
265 };
266 
267 class Movie : public IMovie {
268  public:
269  Movie() {
270  width = 0;
271  height = 0;
272  format_ctx = nullptr;
273  playback_time = 0.0;
274 
276 
277  audio_data_in_device = nullptr;
278  ioBuffer = nullptr;
279  format_ctx = nullptr;
280  avioContext = nullptr;
281 
282  looping = false;
283  playing = false;
284  }
285 
286  virtual ~Movie() { Close(); }
287 
288  void Close() {
289  ReleaseAVCodec();
290 
291  if (audio_data_in_device) {
293  }
294  }
295 
296  inline void ReleaseAVCodec() {
297  audio.close();
298  video.close();
299 
300  if (format_ctx) {
301  // Close the video file
303  logger->Warning(L"close video format context file\n");
304  format_ctx = nullptr;
305  }
306  if (avioContext) {
308  avioContext = nullptr;
309  }
310  if (ioBuffer) {
311  // av_free(ioBuffer);
312  ioBuffer = nullptr;
313  }
314  }
315 
316  bool Load(const char *filename) { // Загрузка
317  // Open video file
318  if (avformat_open_input(&format_ctx, filename, nullptr, nullptr) < 0) {
319  logger->Warning(L"ffmpeg: Unable to open input file");
320  Close();
321  return false;
322  }
323 
324  // Retrieve stream information
325  if (avformat_find_stream_info(format_ctx, nullptr) < 0) {
326  fprintf(stderr, "ffmpeg: Unable to find stream info\n");
327  Close();
328  return false;
329  }
330 
331  // Dump information about file onto standard error
332  av_dump_format(format_ctx, 0, filename, 0);
333 
335 
336  if (!video.open(format_ctx)) {
337  Error("Cannot open video stream: %s", filename);
338  Close();
339  return false;
340  }
341 
342  width = video.width;
343  height = video.height;
344 
345  if (audio.stream_idx >= 0) {
347  }
348 
349  return true;
350  }
351 
352  bool LoadFromLOD(FILE *f, size_t size, size_t offset) {
353  hFile = f;
354  uFileSize = size;
356  uFilePos = 0;
357 
358  if (!ioBuffer) {
359  ioBuffer = (unsigned char *)av_malloc(AV_INPUT_BUFFER_MIN_SIZE); // can get av_free()ed by libav
360  }
361 
362  if (!avioContext) {
363  avioContext = avio_alloc_context(ioBuffer, 0x4000, 0, this, s_read, NULL, s_seek);
364  }
365  if (!format_ctx) {
367  }
369  return Load("dummyFilename");
370  }
371 
372  virtual PMemBuffer GetFrame() {
373  if (!playing) {
374  return nullptr;
375  }
376 
377  auto current_time = std::chrono::system_clock::now();
378  std::chrono::duration<double, std::ratio<1>> diff = current_time - start_time;
379  std::chrono::milliseconds diff_ms = std::chrono::duration_cast<std::chrono::milliseconds>(diff);
380  playback_time += diff_ms.count();
381  start_time = std::chrono::system_clock::now();
382 
383  int desired_frame_number = (int)((playback_time / video.frame_len) + 0.5);
384  if (last_resampled_frame_num == desired_frame_number) {
385  return video.last_frame;
386  }
389  if (looping) {
390  video.reset();
391  audio.reset();
392  int err = av_seek_frame(format_ctx, -1, 0,
393  AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY);
394  char err_buf[2048];
395  av_strerror(err, err_buf, 2048);
396  if (err < 0) {
397  Close();
398  return nullptr;
399  }
401  playback_time = 0;
402  desired_frame_number = 0;
403  } else {
404  playing = false;
405  return nullptr;
406  }
407  }
408 
409  AVPacket *avpacket = av_packet_alloc();
410 
411  // keep reading packets until we hit the end or find a video packet
412  do {
413  if (av_read_frame(format_ctx, avpacket) < 0) {
414  // probably movie is finished
415  playing = false;
416  av_packet_free(&avpacket);
417  return nullptr;
418  }
419 
420  // Is this a packet from the video stream?
421  // audio packet - queue into playing
422  if (avpacket->stream_index == audio.stream_idx) {
423  PMemBuffer buffer = audio.decode_frame(avpacket);
424  if (buffer) {
426  buffer->GetSize() / 2,
427  buffer->GetData());
428  }
429  } else if (avpacket->stream_index == video.stream_idx) {
430  // Decode video frame
431  // video packet - decode & maybe show
432  video.decode_frame(avpacket);
433  } else {
434  assert(false); // unknown stream
435  }
436  } while (avpacket->stream_index != video.stream_idx ||
437  avpacket->pts != desired_frame_number);
438 
439  av_packet_free(&avpacket);
440 
441  return video.last_frame;
442  }
443 
444  virtual unsigned int GetWidth() const { return width; }
445 
446  virtual unsigned int GetHeight() const { return height; }
447 
448  virtual bool Play(bool loop = false) {
449  start_time = std::chrono::system_clock::now();
450  looping = loop;
451  playing = true;
452  return false;
453  }
454 
455  virtual bool Stop() {
456  playing = false;
457  return false;
458  }
459 
460  virtual bool IsPlaing() const { return playing; }
461 
462  protected:
463  static int s_read(void *opaque, uint8_t *buf, int buf_size) {
464  Movie *_this = (Movie *)opaque;
465  return _this->read(opaque, buf, buf_size);
466  }
467 
468  static int64_t s_seek(void *opaque, int64_t offset, int whence) {
469  Movie *_this = (Movie *)opaque;
470  return _this->seek(opaque, offset, whence);
471  }
472 
473  int read(void *opaque, uint8_t *buf, int buf_size) {
474  fseek(hFile, uFileOffset + uFilePos, SEEK_SET);
475  buf_size = std::min(buf_size, (int)uFileSize - (int)uFilePos);
476  buf_size = fread(buf, 1, buf_size, hFile);
477  uFilePos += buf_size;
478  return buf_size;
479  }
480 
481  int64_t seek(void *opaque, int64_t offset, int whence) {
482  if (whence == AVSEEK_SIZE) {
483  return uFileSize;
484  }
485 
486  switch (whence) {
487  case SEEK_SET:
489  break;
490  case SEEK_CUR:
491  uFilePos += (size_t)offset;
492  break;
493  case SEEK_END:
495  break;
496  default:
497  assert(false);
498  break;
499  }
500  fseek(hFile, uFileOffset + uFilePos, SEEK_SET);
501  return uFilePos;
502  }
503 
504  protected:
505  unsigned int width;
506  unsigned int height;
509 
511  unsigned char *ioBuffer;
514 
517 
518  std::chrono::time_point<std::chrono::system_clock> start_time;
519  bool looping;
520  bool playing;
521 
522  FILE *hFile;
523  size_t uFileSize;
524  size_t uFileOffset;
525  size_t uFilePos;
526 };
527 
528 // for video/////////////////////////////////////////////////////////////////
529 
530 class VideoList {
531  protected:
532 #pragma pack(push, 1)
533  struct MovieHeader {
534  char pVideoName[40];
535  unsigned int uFileOffset;
536  };
537 #pragma pack(pop)
538 
539  struct Node {
540  size_t offset;
541  size_t size;
542  };
543  typedef std::map<std::string, Node> Nodes;
544 
545  public:
546  VideoList() { file = nullptr; }
547 
548  virtual ~VideoList() {
549  if (file != nullptr) {
550  fclose(file);
551  file = nullptr;
552  }
553  }
554 
555  void Initialize(const std::string &file_path) {
556  static_assert(sizeof(MovieHeader) == 44, "Wrong type size");
557 
558  if (engine->config->NoVideo()) {
559  return;
560  }
561 
562  file = fopen(file_path.c_str(), "rb");
563  if (file == nullptr) {
564  logger->Warning(L"Can't open video file: %S", file_path.c_str());
565  return;
566  }
567  fseek(file, 0, SEEK_END);
568  size_t file_size = ftell(file);
569  fseek(file, 0, SEEK_SET);
570 
571  uint32_t uNumVideoHeaders = 0;
572  fread(&uNumVideoHeaders, 1, 4, file);
573 
574  std::vector<MovieHeader> headers;
575  headers.resize(uNumVideoHeaders);
576  if (fread(&headers[0], sizeof(MovieHeader), uNumVideoHeaders, file) !=
577  uNumVideoHeaders) {
578  return;
579  }
580  std::sort(headers.begin(), headers.end(),
581  [](MovieHeader &a, MovieHeader &b) {
582  return a.uFileOffset < b.uFileOffset;
583  });
584 
585  for (size_t i = 0; i < headers.size(); i++) {
586  std::string name = headers[i].pVideoName;
587  std::transform(name.begin(), name.end(), name.begin(), ::tolower);
588  Node node;
589  node.offset = headers[i].uFileOffset;
590  if (i < headers.size() - 1) {
591  node.size = headers[i + 1].uFileOffset - headers[i].uFileOffset;
592  } else {
593  node.size = file_size - headers[i].uFileOffset;
594  }
595  nodes[name] = node;
596  }
597  }
598 
599  bool find(const std::string &video_name, FILE *&file_, size_t &offset,
600  size_t &size) {
601  file_ = nullptr;
602  offset = 0;
603  size = 0;
604 
605  std::string name = video_name;
606  std::transform(name.begin(), name.end(), name.begin(), ::tolower);
607  Nodes::iterator it = nodes.find(name);
608  if (it != nodes.end()) {
609  file_ = file;
610  offset = it->second.offset;
611  size = it->second.size;
612  return true;
613  }
614 
615  return false;
616  }
617 
618  protected:
620  FILE *file;
621 };
622 
624  might_list = new VideoList();
625  std::string filename = MakeDataPath("anims\\might7.vid");
626  might_list->Initialize(filename);
627 
628  magic_list = new VideoList();
629  filename = MakeDataPath("anims\\magic7.vid");
630  magic_list->Initialize(filename);
631 }
632 
633 void MPlayer::OpenHouseMovie(const std::string &pMovieName, bool bLoop) {
634  if (IsMoviePlaying()) {
635  return;
636  }
637 
638  pEventTimer->Pause();
640  size_t size = 0;
641  size_t offset = 0;
642  FILE *file = LoadMovie(pMovieName, size, offset);
643  if (file == nullptr) {
644  return;
645  }
646 
647  std::shared_ptr<Movie> pMovie = std::make_shared<Movie>();
648  pMovie->LoadFromLOD(file, size, offset);
649  pMovie_Track = std::dynamic_pointer_cast<IMovie>(pMovie);
650  sInHouseMovie = pMovieName;
651 }
652 
654  if (!pMovie_Track || engine->config->NoVideo()) {
655  return;
656  }
657 
658  if (!pMovie_Track->IsPlaing()) {
659  pMovie_Track->Play(false);
660  }
661 
662  render->BeginScene();
663 
664  static Texture *tex;
665  if (!tex) {
666  tex = render->CreateTexture_Blank(pMovie_Track->GetWidth(), pMovie_Track->GetHeight(), IMAGE_FORMAT_A8R8G8B8);
667  }
668 
669  PMemBuffer buffer = pMovie_Track->GetFrame();
670  if (buffer) {
671  Rect rect;
672  rect.x = 8;
673  rect.y = 8;
674  rect.z = rect.x + game_viewport_width;
675  rect.w = rect.y + game_viewport_height;
676 
677  // update pixels from buffer
679  unsigned int num_pixels = tex->GetWidth() * tex->GetHeight();
680  unsigned int num_pixels_bytes = num_pixels * IMAGE_FORMAT_BytesPerPixel(IMAGE_FORMAT_A8R8G8B8);
681  memcpy(pix, buffer->GetData(), num_pixels_bytes);
682 
683  // update texture
684  render->Update_Texture(tex);
685  render->DrawImage(tex, rect);
686 
687  } else {
688  pMovie_Track = nullptr;
689  size_t size = 0;
690  size_t offset = 0;
691  FILE *file = LoadMovie(sInHouseMovie, size, offset);
692  if (file != nullptr) {
693  std::shared_ptr<Movie> pMovie = std::make_shared<Movie>();
694  pMovie->LoadFromLOD(file, size, offset);
695  pMovie_Track = std::dynamic_pointer_cast<IMovie>(pMovie);
696  pMovie_Track->Play();
697  }
698  // callback to prevent skipped frame draw
699  HouseMovieLoop();
700  }
701 
702  render->EndScene();
703 }
704 
706  if (engine->config->NoVideo()) {
707  return;
708  }
709 
710  size_t size = 0;
711  size_t offset = 0;
712  FILE *file = LoadMovie(pFilename, size, offset);
713  if (file == nullptr) {
714  return;
715  }
716 
717  std::shared_ptr<Movie> pMovie = std::make_shared<Movie>();
718  if (!pMovie->LoadFromLOD(file, size, offset)) {
719  return;
720  }
721  pMovie_Track = std::dynamic_pointer_cast<IMovie>(pMovie);
722 
723  pEventTimer->Pause();
725  OS_ShowCursor(false);
727 
728  pMovie_Track->Play();
729 
730  Rect rect;
731  rect.x = 0;
732  rect.y = 0;
733  rect.z = rect.x + 640;
734  rect.w = rect.y + 480;
735 
736  // create texture
737  Texture *tex = render->CreateTexture_Blank(pMovie_Track->GetWidth(), pMovie_Track->GetHeight(), IMAGE_FORMAT_A8R8G8B8);
738 
739  while (true) {
740  render->BeginScene();
741 
742  window->PeekMessageLoop();
743 
744  // if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE) continue;
745  // add pausing of movie when game lost focus
746 
747  OS_Sleep(2);
748 
749  PMemBuffer buffer = pMovie_Track->GetFrame();
750  if (!buffer) {
751  break;
752  }
753 
754  // update pixels from buffer
756  unsigned int num_pixels = tex->GetWidth() * tex->GetHeight();
757  unsigned int num_pixels_bytes = num_pixels * IMAGE_FORMAT_BytesPerPixel(IMAGE_FORMAT_A8R8G8B8);
758  memcpy(pix, buffer->GetData(), num_pixels_bytes);
759 
760  // update texture
761  render->Update_Texture(tex);
762  render->DrawImage(tex, rect);
763 
764  render->EndScene();
765  render->Present();
766  }
767 
768  // release texture
769  tex->Release();
770 
772  pMovie_Track = nullptr;
773 
774  OS_ShowCursor(true);
775 }
776 
778  if (!pMovie_Track) {
779  return false;
780  }
781 
782  return pMovie_Track->IsPlaing();
783 }
784 
786  if (pMovie_Track) {
787  return pMovie_Track->Stop();
788  }
789  return false;
790 }
791 
792 FILE *MPlayer::LoadMovie(const std::string &video_name, size_t &size,
793  size_t &offset) {
794  std::string pVideoNameBik = video_name + ".bik";
795  std::transform(pVideoNameBik.begin(), pVideoNameBik.end(),
796  pVideoNameBik.begin(), ::tolower);
797  std::string pVideoNameSmk = video_name + ".smk";
798  std::transform(pVideoNameSmk.begin(), pVideoNameSmk.end(),
799  pVideoNameSmk.begin(), ::tolower);
800 
801  FILE *file = nullptr;
802  offset = 0;
803  size = 0;
804 
805  if (might_list != nullptr) {
806  if (might_list->find(pVideoNameBik, file, offset, size)) {
807  return file;
808  }
809  if (might_list->find(pVideoNameSmk, file, offset, size)) {
810  return file;
811  }
812  }
813 
814  if (magic_list != nullptr) {
815  if (magic_list->find(pVideoNameBik, file, offset, size)) {
816  return file;
817  }
818  if (magic_list->find(pVideoNameSmk, file, offset, size)) {
819  return file;
820  }
821  }
822 
823  return nullptr;
824 }
825 
827  if (pMovie_Track) {
828  pMovie_Track->Stop();
829  }
830  pMovie_Track = nullptr;
831  if (!bGameoverLoop) {
833  }
834  pEventTimer->Resume();
835 }
836 
837 // for video//////////////////////////////////////////////////////////////////
838 
839 void av_logger(void *ptr, int level, const char *format, va_list args) {
840  char buf[2048];
841  int prefix = 1;
842  av_log_format_line(ptr, level, format, args, buf, 2048, &prefix);
843  log("av: %s", buf);
844 }
845 
847  static int libavcodec_initialized = false;
848 
849  if (!libavcodec_initialized) {
851  // Register all available file formats and codecs
852 #ifndef FF_API_NEXT
854  av_register_all();
855 #endif
856  libavcodec_initialized = true;
857  }
858 
859  pMovie_Track = nullptr;
860 
861  if (!provider) {
863  // logger->Warning(L"allocation dynamic memory for provider\n");
864  provider->Initialize();
865  }
866 }
867 
869  if (might_list != nullptr) {
870  delete might_list;
871  might_list = nullptr;
872  }
873 
874  if (magic_list != nullptr) {
875  delete magic_list;
876  magic_list = nullptr;
877  }
878 
879  delete provider;
880 }
881 
882 // AudioBaseDataSource
883 
885  public:
887  virtual ~AudioBaseDataSource() { Close(); }
888 
889  virtual bool Open();
890  virtual void Close();
891 
892  virtual size_t GetSampleRate();
893  virtual size_t GetChannelCount();
894  virtual PMemBuffer GetNextBuffer();
895 
896  protected:
901  bool bOpened;
902  std::queue<PMemBuffer, std::deque<PMemBuffer>> queue;
903 };
904 
906  pFormatContext = nullptr;
907  iStreamIndex = -1;
908  pCodecContext = nullptr;
909  pConverter = nullptr;
910  bOpened = false;
911 }
912 
914  // Retrieve stream information
915  if (avformat_find_stream_info(pFormatContext, nullptr) < 0) {
916  Close();
917  fprintf(stderr, "ffmpeg: Unable to find stream info\n");
918  return false;
919  }
920 
921  AVCodec *codec = nullptr;
923  -1, &codec, 0);
924  if (iStreamIndex < 0) {
925  Close();
926  fprintf(stderr, "ffmpeg: Unable to find audio stream\n");
927  return false;
928  }
929 
932  if (pCodecContext == nullptr) {
933  Close();
934  return false;
935  }
936 
937  if (avcodec_parameters_to_context(pCodecContext, stream->codecpar) < 0) {
938  Close();
939  return false;
940  }
941  if (avcodec_open2(pCodecContext, codec, nullptr) < 0) {
942  Close();
943  return false;
944  }
945 
947  pConverter,
949  : AV_CH_LAYOUT_MONO,
952  : AV_CH_LAYOUT_MONO,
954  if (swr_init(pConverter) < 0) {
955  Close();
956  fprintf(stderr, "ffmpeg: Failed to create converter\n");
957  return false;
958  }
959 
960  bOpened = true;
961 
962  return true;
963 }
964 
966  if (pConverter != nullptr) {
968  pConverter = nullptr;
969  }
970 
971  if (pCodecContext) {
973  pCodecContext = nullptr;
974  }
975 
976  iStreamIndex = -1;
977 
978  if (pFormatContext != nullptr) {
980  pFormatContext = nullptr;
981  }
982 }
983 
985  if (pCodecContext == nullptr) {
986  return 0;
987  }
988 
989  return pCodecContext->sample_rate;
990 }
991 
993  if (pCodecContext == nullptr) {
994  return 0;
995  }
996 
997  return pCodecContext->channels;
998 }
999 
1002 
1003  if (!queue.empty()) {
1004  buffer = queue.front();
1005  queue.pop();
1006  }
1007 
1008  AVPacket *packet = av_packet_alloc();
1009 
1010  if (av_read_frame(pFormatContext, packet) >= 0) {
1011  if (avcodec_send_packet(pCodecContext, packet) >= 0) {
1013  AVFrame *frame = av_frame_alloc();
1014  int res = 0;
1015  while (res >= 0) {
1017  if (res == AVERROR(EAGAIN) || res == AVERROR_EOF) {
1018  break;
1019  }
1020  if (res < 0) {
1021  return buffer;
1022  }
1023  PMemBuffer tmp_buf = AllocMemBuffer(
1024  frame->nb_samples * pCodecContext->channels * 2);
1025  uint8_t *dst_channels[8] = {0};
1026  dst_channels[0] = (uint8_t *)tmp_buf->GetData();
1027  int got_samples = swr_convert(
1028  pConverter, dst_channels, frame->nb_samples,
1029  (const uint8_t **)frame->data, frame->nb_samples);
1030  if (got_samples > 0) {
1031  if (!buffer) {
1032  buffer = tmp_buf;
1033  } else {
1034  queue.push(tmp_buf);
1035  }
1036  }
1037  }
1038  av_frame_free(&frame);
1039  }
1040  }
1041 
1042  av_packet_free(&packet);
1043 
1044  return buffer;
1045 }
1046 
1047 // AudioFileDataSource
1048 
1050  public:
1051  explicit AudioFileDataSource(const std::string &file_name);
1053 
1054  virtual bool Open();
1055 
1056  protected:
1058 };
1059 
1061  sFileName = file_name;
1062 }
1063 
1065  if (bOpened) {
1066  return true;
1067  }
1068 
1069  // Open audio file
1070  if (avformat_open_input(&pFormatContext, sFileName.c_str(), nullptr,
1071  nullptr) < 0) {
1072  fprintf(stderr, "ffmpeg: Unable to open input file\n");
1073  return false;
1074  }
1075 
1076  // Dump information about file onto standard error
1077  av_dump_format(pFormatContext, 0, sFileName.c_str(), 0);
1078 
1079  return AudioBaseDataSource::Open();
1080 }
1081 
1082 // AudioBufferDataSource
1083 
1085  public:
1088 
1089  bool Open();
1090 
1091  protected:
1098 
1099  static int read_packet(void *opaque, uint8_t *buf, int buf_size);
1100  int ReadPacket(uint8_t *buf, int buf_size);
1101 };
1102 
1104  : buffer(buffer) {
1105  buf_pos = nullptr;
1106  buf_end = nullptr;
1107  avio_ctx_buffer = nullptr;
1108  avio_ctx_buffer_size = 4096;
1109  avio_ctx = nullptr;
1110 }
1111 
1113  if (bOpened) {
1114  return true;
1115  }
1116 
1118  if (pFormatContext == nullptr) {
1119  return false;
1120  }
1121 
1123  if (avio_ctx_buffer == nullptr) {
1124  Close();
1125  return false;
1126  }
1127 
1129  this, &read_packet, nullptr, nullptr);
1130  if (!avio_ctx) {
1131  Close();
1132  return false;
1133  }
1134 
1136 
1137  buf_pos = (uint8_t*)buffer->GetData();
1138  buf_end = buf_pos + buffer->GetSize();
1139 
1140  // Open audio file
1141  if (avformat_open_input(&pFormatContext, nullptr, nullptr, nullptr) < 0) {
1142  fprintf(stderr, "ffmpeg: Unable to open input buffer\n");
1143  return false;
1144  }
1145 
1146  // Dump information about buffer onto standard error
1147  av_dump_format(pFormatContext, 0, nullptr, 0);
1148 
1149  return AudioBaseDataSource::Open();
1150 }
1151 
1153  int buf_size) {
1154  AudioBufferDataSource *pThis = (AudioBufferDataSource *)opaque;
1155  return pThis->ReadPacket(buf, buf_size);
1156 }
1157 
1159  int size = buf_end - buf_pos;
1160  if (size <= 0) {
1161  return 0;
1162  }
1163  size = std::min(buf_size, size);
1164  memcpy(buf, buf_pos, size);
1165  buf_pos += size;
1166  return size;
1167 }
1168 
1170  std::shared_ptr<AudioFileDataSource> source =
1171  std::make_shared<AudioFileDataSource>(file_name);
1172  return std::dynamic_pointer_cast<IAudioDataSource, AudioFileDataSource>(
1173  source);
1174 }
1175 
1177  std::shared_ptr<AudioBufferDataSource> source =
1178  std::make_shared<AudioBufferDataSource>(buffer);
1179  return std::dynamic_pointer_cast<IAudioDataSource, AudioBufferDataSource>(
1180  source);
1181 }
Movie::video
AVVideoStream video
Definition: MediaPlayer.cpp:515
avcodec_close
int avcodec_close(AVCodecContext *avctx)
AVStreamWrapper::dec
AVCodec * dec
Definition: MediaPlayer.cpp:111
AVCodecContext
Definition: avcodec.h:1565
MPlayer::sInHouseMovie
std::string sInHouseMovie
Definition: MediaPlayer.h:36
opt.h
AVCodecContext::height
int height
Definition: avcodec.h:1738
Movie::GetWidth
virtual unsigned int GetWidth() const
Definition: MediaPlayer.cpp:444
Image::GetHeight
unsigned int GetHeight()
Definition: Image.cpp:230
AudioBaseDataSource::GetNextBuffer
virtual PMemBuffer GetNextBuffer()
Definition: MediaPlayer.cpp:1000
MPlayer::PlayFullscreenMovie
void PlayFullscreenMovie(const std::string &pMovieName)
Definition: MediaPlayer.cpp:705
AVStreamWrapper::reset
virtual void reset()
Definition: MediaPlayer.cpp:60
Movie::LoadFromLOD
bool LoadFromLOD(FILE *f, size_t size, size_t offset)
Definition: MediaPlayer.cpp:352
Movie::uFileSize
size_t uFileSize
Definition: MediaPlayer.cpp:523
OS_ShowCursor
void OS_ShowCursor(bool show)
Definition: Lin.cpp:28
Rect::x
int x
Definition: Rect.h:4
Timer::Resume
void Resume()
Definition: Time.cpp:27
OpenALSoundProvider::StreamingTrackBuffer
Definition: OpenALSoundProvider.h:19
AVIOContext
Definition: avio.h:161
av_frame_free
void av_frame_free(AVFrame **frame)
AudioFileDataSource
Definition: MediaPlayer.cpp:1049
AudioBaseDataSource::iStreamIndex
int iStreamIndex
Definition: MediaPlayer.cpp:898
AVStreamWrapper::close
virtual void close()
Definition: MediaPlayer.cpp:66
av_malloc
void * av_malloc(size_t size) av_malloc_attrib av_alloc_size(1)
VideoList::MovieHeader::uFileOffset
unsigned int uFileOffset
Definition: MediaPlayer.cpp:535
AVAudioStream
Definition: MediaPlayer.cpp:116
VideoList::MovieHeader
Definition: MediaPlayer.cpp:533
source
GLsizei GLsizei GLchar * source
Definition: SDL_opengl_glext.h:680
AVVideoStream::decode_frame
PMemBuffer decode_frame(AVPacket *avpacket)
Definition: MediaPlayer.cpp:211
Rect::w
int w
Definition: Rect.h:7
VideoList::~VideoList
virtual ~VideoList()
Definition: MediaPlayer.cpp:548
height
EGLSurface EGLint EGLint EGLint EGLint height
Definition: SDL_egl.h:1596
AVVideoStream::last_frame
PMemBuffer last_frame
Definition: MediaPlayer.cpp:259
avcodec_register_all
attribute_deprecated void avcodec_register_all(void)
OpenALSoundProvider::Initialize
bool Initialize()
Definition: OpenALSoundProvider.cpp:50
level
GLint level
Definition: SDL_opengl.h:1572
VideoList::Node
Definition: MediaPlayer.cpp:539
Movie::s_read
static int s_read(void *opaque, uint8_t *buf, int buf_size)
Definition: MediaPlayer.cpp:463
AudioFileDataSource::~AudioFileDataSource
virtual ~AudioFileDataSource()
Definition: MediaPlayer.cpp:1052
sws_scale
int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Movie::Stop
virtual bool Stop()
Definition: MediaPlayer.cpp:455
engine
std::shared_ptr< Engine > engine
Definition: Engine.cpp:130
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
AudioPlayer::MusicResume
void MusicResume()
Definition: AudioPlayer.cpp:157
Rect::z
int z
Definition: Rect.h:6
Texture
Definition: Texture.h:4
game_viewport_width
unsigned int game_viewport_width
Definition: mm7_data.cpp:194
Movie
Definition: MediaPlayer.cpp:267
MPlayer::StopMovie
bool StopMovie()
Definition: MediaPlayer.cpp:785
av_packet_free
void av_packet_free(AVPacket **pkt)
Movie::hFile
FILE * hFile
Definition: MediaPlayer.cpp:522
IMovie
Definition: Media.h:76
IMAGE_FORMAT_BytesPerPixel
unsigned int IMAGE_FORMAT_BytesPerPixel(IMAGE_FORMAT format)
Definition: Image.cpp:46
PAudioDataSource
std::shared_ptr< IAudioDataSource > PAudioDataSource
Definition: Media.h:20
MPlayer::MPlayer
MPlayer()
Definition: MediaPlayer.cpp:846
AVVideoStream::AVVideoStream
AVVideoStream()
Definition: MediaPlayer.cpp:187
pMediaPlayer
MPlayer * pMediaPlayer
Definition: MediaPlayer.cpp:43
avformat_close_input
void avformat_close_input(AVFormatContext **s)
Movie::Close
void Close()
Definition: MediaPlayer.cpp:288
int64_t
__int64 int64_t
Definition: alext.h:31
AudioBufferDataSource::buffer
PMemBuffer buffer
Definition: MediaPlayer.cpp:1092
AudioFileDataSource::Open
virtual bool Open()
Definition: MediaPlayer.cpp:1064
AudioBufferDataSource
Definition: MediaPlayer.cpp:1084
av_strerror
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
AudioBaseDataSource::~AudioBaseDataSource
virtual ~AudioBaseDataSource()
Definition: MediaPlayer.cpp:887
pMovie_Track
PMovie pMovie_Track
Definition: MediaPlayer.cpp:44
VideoList::Nodes
std::map< std::string, Node > Nodes
Definition: MediaPlayer.cpp:543
AVVideoStream::frame_len
double frame_len
Definition: MediaPlayer.cpp:261
VideoList
Definition: MediaPlayer.cpp:530
MPlayer::might_list
VideoList * might_list
Definition: MediaPlayer.h:34
AVStreamWrapper::dec_ctx
AVCodecContext * dec_ctx
Definition: MediaPlayer.cpp:112
AVStreamWrapper::AVStreamWrapper
AVStreamWrapper()
Definition: MediaPlayer.cpp:48
Movie::GetHeight
virtual unsigned int GetHeight() const
Definition: MediaPlayer.cpp:446
AudioBaseDataSource::GetChannelCount
virtual size_t GetChannelCount()
Definition: MediaPlayer.cpp:992
game_viewport_height
unsigned int game_viewport_height
Definition: mm7_data.cpp:195
size_t
unsigned int size_t
Definition: SDL_config.h:68
av_frame_alloc
AVFrame * av_frame_alloc(void)
VideoList::find
bool find(const std::string &video_name, FILE *&file_, size_t &offset, size_t &size)
Definition: MediaPlayer.cpp:599
AudioBufferDataSource::buf_end
uint8_t * buf_end
Definition: MediaPlayer.cpp:1094
AVAudioStream::AVAudioStream
AVAudioStream()
Definition: MediaPlayer.cpp:118
Movie::Play
virtual bool Play(bool loop=false)
Definition: MediaPlayer.cpp:448
Engine.h
current_screen_type
enum CURRENT_SCREEN current_screen_type
Definition: GUIWindow.cpp:83
AVPacket::stream_index
int stream_index
Definition: avcodec.h:1479
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9435
av_dump_format
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Movie::ioBuffer
unsigned char * ioBuffer
Definition: MediaPlayer.cpp:511
swr_init
int swr_init(struct SwrContext *s)
AudioBufferDataSource::avio_ctx
AVIOContext * avio_ctx
Definition: MediaPlayer.cpp:1097
av_log_format_line
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, char *line, int line_size, int *print_prefix)
AudioBufferDataSource::buf_pos
uint8_t * buf_pos
Definition: MediaPlayer.cpp:1093
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
av_register_all
attribute_deprecated void av_register_all(void)
av_image_fill_linesizes
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
MPlayer::~MPlayer
virtual ~MPlayer()
Definition: MediaPlayer.cpp:868
VideoList::Initialize
void Initialize(const std::string &file_path)
Definition: MediaPlayer.cpp:555
IAudioDataSource
Definition: Media.h:8
AudioFileDataSource::AudioFileDataSource
AudioFileDataSource(const std::string &file_name)
Definition: MediaPlayer.cpp:1060
IMAGE_FORMAT_A8R8G8B8
@ IMAGE_FORMAT_A8R8G8B8
Definition: Image.h:7
av_seek_frame
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
format
SDL_AudioFormat format
Definition: SDL_audio.h:194
MPlayer::OpenHouseMovie
void OpenHouseMovie(const std::string &pMovieName, bool bLoop)
Definition: MediaPlayer.cpp:633
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
buffer
EGLContext EGLenum EGLClientBuffer buffer
Definition: SDL_egl.h:952
av_q2d
static double av_q2d(AVRational a)
Definition: rational.h:104
MPlayer::LoadMovie
FILE * LoadMovie(const std::string &video_name, size_t &size, size_t &offset)
Definition: MediaPlayer.cpp:792
AudioBaseDataSource
Definition: MediaPlayer.cpp:884
Image::GetWidth
unsigned int GetWidth()
Definition: Image.cpp:217
avcodec_receive_frame
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
VideoList::Node::offset
size_t offset
Definition: MediaPlayer.cpp:540
AllocMemBuffer
PMemBuffer AllocMemBuffer(size_t size)
Definition: MemBuffer.cpp:20
Movie::start_time
std::chrono::time_point< std::chrono::system_clock > start_time
Definition: MediaPlayer.cpp:518
AudioBaseDataSource::bOpened
bool bOpened
Definition: MediaPlayer.cpp:901
Movie::~Movie
virtual ~Movie()
Definition: MediaPlayer.cpp:286
buf
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: SDL_opengl_glext.h:2483
AVPacket::pts
int64_t pts
Definition: avcodec.h:1470
Movie::Movie
Movie()
Definition: MediaPlayer.cpp:269
IRender.h
swr_alloc_set_opts
struct SwrContext * swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx)
ErrorHandling.h
OS_Sleep
void OS_Sleep(int ms)
Definition: Lin.cpp:36
OpenALSoundProvider::CreateStreamingTrack16
StreamingTrackBuffer * CreateStreamingTrack16(int num_channels, int sample_rate, int bytes_per_sample)
Definition: OpenALSoundProvider.cpp:173
AudioBaseDataSource::AudioBaseDataSource
AudioBaseDataSource()
Definition: MediaPlayer.cpp:905
AVVideoStream::open
virtual bool open(AVFormatContext *format_ctx)
Definition: MediaPlayer.cpp:193
AVVideoStream::width
int width
Definition: MediaPlayer.cpp:263
AVVideoStream
Definition: MediaPlayer.cpp:185
VideoList::Node::size
size_t size
Definition: MediaPlayer.cpp:541
Movie::playing
bool playing
Definition: MediaPlayer.cpp:520
MPlayer::Unload
void Unload()
Definition: MediaPlayer.cpp:826
Movie::last_resampled_frame_num
int last_resampled_frame_num
Definition: MediaPlayer.cpp:516
AVStreamWrapper::type
AVMediaType type
Definition: MediaPlayer.cpp:108
avcodec_open2
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
OpenALSoundProvider::DeleteStreamingTrack
void DeleteStreamingTrack(StreamingTrackBuffer **buffer)
Definition: OpenALSoundProvider.cpp:116
width
EGLSurface EGLint EGLint EGLint width
Definition: SDL_egl.h:1596
Log::Warning
void Warning(const wchar_t *pFormat,...)
Definition: Log.cpp:28
AudioBaseDataSource::pFormatContext
AVFormatContext * pFormatContext
Definition: MediaPlayer.cpp:897
AVStreamWrapper::open
virtual bool open(AVFormatContext *format_ctx, AVMediaType type_)
Definition: MediaPlayer.cpp:81
Movie::uFileOffset
size_t uFileOffset
Definition: MediaPlayer.cpp:524
swresample.h
MediaPlayer.h
AVFrame::height
int height
Definition: frame.h:353
AVStreamWrapper::open
virtual bool open(AVFormatContext *format_ctx)=0
Movie::uFilePos
size_t uFilePos
Definition: MediaPlayer.cpp:525
Movie::Load
bool Load(const char *filename)
Definition: MediaPlayer.cpp:316
window
EGLSurface EGLNativeWindowType * window
Definition: SDL_egl.h:1580
avformat_find_stream_info
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
AudioBufferDataSource::avio_ctx_buffer
uint8_t * avio_ctx_buffer
Definition: MediaPlayer.cpp:1095
type
EGLenum type
Definition: SDL_egl.h:850
AVMediaType
AVMediaType
Definition: avutil.h:199
av_log_set_callback
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
AudioFileDataSource::sFileName
std::string sFileName
Definition: MediaPlayer.cpp:1057
sws_getContext
struct SwsContext * sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
SwrContext
struct SwrContext SwrContext
Definition: swresample.h:182
Timer::Pause
void Pause()
Definition: Time.cpp:19
Rect
Definition: Rect.h:3
Movie::format_ctx
AVFormatContext * format_ctx
Definition: MediaPlayer.cpp:507
swr_free
void swr_free(struct SwrContext **s)
AVCodecContext::width
int width
Definition: avcodec.h:1738
swr_convert
int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in, int in_count)
MPlayer::HouseMovieLoop
void HouseMovieLoop()
Definition: MediaPlayer.cpp:653
MPlayer::magic_list
VideoList * magic_list
Definition: MediaPlayer.h:35
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
MPlayer
Definition: MediaPlayer.h:17
AVStream::duration
int64_t duration
Definition: avformat.h:921
MPlayer::Initialize
void Initialize()
Definition: MediaPlayer.cpp:623
provider
OpenALSoundProvider * provider
Definition: MediaPlayer.cpp:41
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
Definition: frame.h:326
VideoList::file
FILE * file
Definition: MediaPlayer.cpp:620
av_packet_alloc
AVPacket * av_packet_alloc(void)
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
sample format
Definition: avcodec.h:2233
AudioBaseDataSource::GetSampleRate
virtual size_t GetSampleRate()
Definition: MediaPlayer.cpp:984
stream
EGLStreamKHR stream
Definition: SDL_egl.h:1082
AVVideoStream::height
int height
Definition: MediaPlayer.cpp:264
Movie::IsPlaing
virtual bool IsPlaing() const
Definition: MediaPlayer.cpp:460
avcodec_send_packet
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
AVFormatContext::streams
AVStream ** streams
Definition: avformat.h:1412
AudioBaseDataSource::Open
virtual bool Open()
Definition: MediaPlayer.cpp:913
AVStreamWrapper::~AVStreamWrapper
virtual ~AVStreamWrapper()
Definition: MediaPlayer.cpp:56
AudioPlayer.h
AudioBaseDataSource::pConverter
SwrContext * pConverter
Definition: MediaPlayer.cpp:900
OpenALSoundProvider::Stream16
void Stream16(StreamingTrackBuffer *buffer, int num_samples, const void *samples, bool wait=false)
Definition: OpenALSoundProvider.cpp:226
OpenALSoundProvider.h
avformat_open_input
int avformat_open_input(AVFormatContext **ps, const char *url, ff_const59 AVInputFormat *fmt, AVDictionary **options)
CURRENT_SCREEN::SCREEN_GAME
@ SCREEN_GAME
Movie::height
unsigned int height
Definition: MediaPlayer.cpp:506
CreateAudioBufferDataSource
PAudioDataSource CreateAudioBufferDataSource(PMemBuffer buffer)
Definition: MediaPlayer.cpp:1176
transform
GLuint GLenum GLenum transform
Definition: SDL_opengl_glext.h:9999
AVStreamWrapper::stream
AVStream * stream
Definition: MediaPlayer.cpp:110
avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
AudioBufferDataSource::ReadPacket
int ReadPacket(uint8_t *buf, int buf_size)
Definition: MediaPlayer.cpp:1158
AVFrame::nb_samples
int nb_samples
Definition: frame.h:361
uint8_t
unsigned __int8 uint8_t
Definition: SDL_config.h:35
avio_alloc_context
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1112
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
AudioBaseDataSource::queue
std::queue< PMemBuffer, std::deque< PMemBuffer > > queue
Definition: MediaPlayer.cpp:902
Movie::seek
int64_t seek(void *opaque, int64_t offset, int whence)
Definition: MediaPlayer.cpp:481
Movie::read
int read(void *opaque, uint8_t *buf, int buf_size)
Definition: MediaPlayer.cpp:473
name
EGLImageKHR EGLint * name
Definition: SDL_egl.h:1497
Rect::y
int y
Definition: Rect.h:5
av_free
void av_free(void *ptr)
avcodec.h
Movie::avioContext
AVIOContext * avioContext
Definition: MediaPlayer.cpp:512
MakeDataPath
std::string MakeDataPath(const char *file_rel_path)
Definition: Engine.cpp:126
Movie::ReleaseAVCodec
void ReleaseAVCodec()
Definition: MediaPlayer.cpp:296
avcodec_flush_buffers
void avcodec_flush_buffers(AVCodecContext *avctx)
AVFormatContext::pb
AVIOContext * pb
Definition: avformat.h:1386
AVVideoStream::frames_per_second
double frames_per_second
Definition: MediaPlayer.cpp:260
bGameoverLoop
int bGameoverLoop
Definition: mm7_data.cpp:785
AVPacket
Definition: avcodec.h:1454
AudioBufferDataSource::~AudioBufferDataSource
virtual ~AudioBufferDataSource()
Definition: MediaPlayer.cpp:1087
avformat.h
AVAudioStream::open
virtual bool open(AVFormatContext *format_ctx)
Definition: MediaPlayer.cpp:120
log
void log(const char *format,...)
Definition: OpenALSoundProvider.cpp:24
AudioBufferDataSource::AudioBufferDataSource
AudioBufferDataSource(PMemBuffer buffer)
Definition: MediaPlayer.cpp:1103
OpenALSoundProvider
Definition: OpenALSoundProvider.h:12
VideoList::VideoList
VideoList()
Definition: MediaPlayer.cpp:546
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
Definition: frame.h:309
Movie::looping
bool looping
Definition: MediaPlayer.cpp:519
Image::GetPixels
const void * GetPixels(IMAGE_FORMAT format)
Definition: Image.cpp:270
AudioBufferDataSource::avio_ctx_buffer_size
size_t avio_ctx_buffer_size
Definition: MediaPlayer.cpp:1096
AVFormatContext
Definition: avformat.h:1344
Movie::playback_time
double playback_time
Definition: MediaPlayer.cpp:508
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1112
AVAudioStream::converter
SwrContext * converter
Definition: MediaPlayer.cpp:182
PMovie
std::shared_ptr< IMovie > PMovie
Definition: Media.h:89
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avutil.h
AudioBaseDataSource::Close
virtual void Close()
Definition: MediaPlayer.cpp:965
mem.h
pAudioPlayer
AudioPlayer * pAudioPlayer
Definition: AudioPlayer.cpp:20
Movie::width
unsigned int width
Definition: MediaPlayer.cpp:505
AVStreamWrapper::queue
std::queue< PMemBuffer, std::deque< PMemBuffer > > queue
Definition: MediaPlayer.cpp:113
string
GLsizei const GLchar *const * string
Definition: SDL_opengl_glext.h:691
AVStream
Definition: avformat.h:872
GUIWindow.h
Movie::s_seek
static int64_t s_seek(void *opaque, int64_t offset, int whence)
Definition: MediaPlayer.cpp:468
size
GLsizeiptr size
Definition: SDL_opengl_glext.h:540
Movie::audio
AVAudioStream audio
Definition: MediaPlayer.cpp:510
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Definition: avcodec.h:1775
offset
GLintptr offset
Definition: SDL_opengl_glext.h:541
logger
Log * logger
Definition: IocContainer.cpp:47
AVCodec
Definition: avcodec.h:3481
Movie::audio_data_in_device
OpenALSoundProvider::StreamingTrackBuffer * audio_data_in_device
Definition: MediaPlayer.cpp:513
AudioBufferDataSource::Open
bool Open()
Definition: MediaPlayer.cpp:1112
AudioPlayer::MusicPause
void MusicPause()
Definition: AudioPlayer.cpp:149
Movie::GetFrame
virtual PMemBuffer GetFrame()
Definition: MediaPlayer.cpp:372
res
GLuint res
Definition: SDL_opengl_glext.h:7940
MPlayer::IsMoviePlaying
bool IsMoviePlaying() const
Definition: MediaPlayer.cpp:777
imgutils.h
AVAudioStream::decode_frame
PMemBuffer decode_frame(AVPacket *avpacket)
Definition: MediaPlayer.cpp:139
PMemBuffer
std::shared_ptr< IMemBuffer > PMemBuffer
Definition: MemBuffer.h:13
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:2226
CreateAudioFileDataSource
PAudioDataSource CreateAudioFileDataSource(const std::string &file_name)
Definition: MediaPlayer.cpp:1169
uint32_t
unsigned __int32 uint32_t
Definition: SDL_config.h:39
AudioBaseDataSource::pCodecContext
AVCodecContext * pCodecContext
Definition: MediaPlayer.cpp:899
AVStreamWrapper
Definition: MediaPlayer.cpp:46
AVFrame
Definition: frame.h:295
AVVideoStream::converter
SwsContext * converter
Definition: MediaPlayer.cpp:262
Log.h
AVStreamWrapper::stream_idx
int stream_idx
Definition: MediaPlayer.cpp:109
pEventTimer
Timer * pEventTimer
Definition: Time.cpp:8
Image::Release
bool Release()
Definition: Image.cpp:335
av_logger
void av_logger(void *ptr, int level, const char *format, va_list args)
Definition: MediaPlayer.cpp:839
VideoList::nodes
Nodes nodes
Definition: MediaPlayer.cpp:619
Mouse.h
CURRENT_SCREEN::SCREEN_VIDEO
@ SCREEN_VIDEO
Api.h
swscale.h
AVCodecContext::channel_layout
uint64_t channel_layout
Definition: avcodec.h:2276
AudioBufferDataSource::read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: MediaPlayer.cpp:1152
VideoList::MovieHeader::pVideoName
char pVideoName[40]
Definition: MediaPlayer.cpp:534
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:2225
av_find_best_stream
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, AVCodec **decoder_ret, int flags)
render
std::shared_ptr< IRender > render
Definition: RenderOpenGL.cpp:52