My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

media_player_screen.cpp 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /***************************
  2. * media_player_screen.cpp *
  3. ***************************/
  4. /****************************************************************************
  5. * Written By Mark Pelletier 2017 - Aleph Objects, Inc. *
  6. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  7. * *
  8. * This program is free software: you can redistribute it and/or modify *
  9. * it under the terms of the GNU General Public License as published by *
  10. * the Free Software Foundation, either version 3 of the License, or *
  11. * (at your option) any later version. *
  12. * *
  13. * This program is distributed in the hope that it will be useful, *
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU General Public License for more details. *
  17. * *
  18. * To view a copy of the GNU General Public License, go to the following *
  19. * location: <http://www.gnu.org/licenses/>. *
  20. ****************************************************************************/
  21. #include "../config.h"
  22. /**
  23. * The MediaPlayerScreen allows an AVI to be played.
  24. *
  25. * It requires a special AVI file. The following video
  26. * and audio codecs must be used:
  27. *
  28. * -vcodec mjpeg -pix_fmt yuvj420p
  29. * -acodec adpcm_ima_wav
  30. *
  31. * To generate a 2 second static screen from a png file:
  32. *
  33. * ffmpeg -i startup.png -vcodec mjpeg -pix_fmt yuvj420p -r 1 video.avi
  34. * sox -n -r 44100 -b 8 -c 2 -L silence.wav trim 0.0 2.000
  35. * ffmpeg -i silence.wav -acodec adpcm_ima_wav silence.avi
  36. * ffmpeg -i video.avi -i silence.wav -c copy -map 0:v:0 -map 1:a:0 startup.avi
  37. */
  38. #if ENABLED(TOUCH_UI_FTDI_EVE)
  39. #include "screens.h"
  40. #include "../archim2-flash/flash_storage.h"
  41. #include "../archim2-flash/media_file_reader.h"
  42. using namespace FTDI;
  43. void MediaPlayerScreen::onEntry() {
  44. BaseScreen::onEntry();
  45. CLCD::turn_on_backlight();
  46. SoundPlayer::set_volume(255);
  47. }
  48. void MediaPlayerScreen::onRedraw(draw_mode_t) {
  49. }
  50. bool MediaPlayerScreen::playCardMedia() {
  51. #if ENABLED(SDSUPPORT)
  52. char fname[15];
  53. strcpy_P(fname, PSTR("STARTUP.AVI"));
  54. MediaFileReader reader;
  55. if (!reader.open(fname))
  56. return false;
  57. SERIAL_ECHO_MSG("Starting to play STARTUP.AVI");
  58. playStream(&reader, MediaFileReader::read);
  59. reader.close();
  60. #endif
  61. return true;
  62. }
  63. // Attempt to play media from the onboard SPI flash chip
  64. bool MediaPlayerScreen::playBootMedia() {
  65. UIFlashStorage::BootMediaReader reader;
  66. if (!reader.isAvailable()) return false;
  67. SERIAL_ECHO_MSG("Starting to play boot video");
  68. playStream(&reader, UIFlashStorage::BootMediaReader::read);
  69. return true;
  70. }
  71. void MediaPlayerScreen::playStream(void *obj, media_streamer_func_t *data_stream) {
  72. #if FTDI_API_LEVEL >= 810
  73. if (FTDI::ftdi_chip >= 810) {
  74. // Set up the media FIFO on the end of RAMG, as the top of RAMG
  75. // will be used as the framebuffer.
  76. uint8_t buf[512];
  77. const uint32_t block_size = 512;
  78. const uint32_t fifo_size = block_size * 2;
  79. const uint32_t fifo_start = CLCD::MAP::RAM_G + CLCD::MAP::RAM_G_SIZE - fifo_size;
  80. CommandProcessor cmd;
  81. cmd.cmd(CMD_DLSTART)
  82. .cmd(CLEAR_COLOR_RGB(0x000000))
  83. .cmd(CLEAR(true,true,true))
  84. .cmd(DL::DL_DISPLAY)
  85. .cmd(CMD_SWAP)
  86. .execute()
  87. .cmd(CMD_DLSTART)
  88. .mediafifo(fifo_start, fifo_size)
  89. .playvideo(OPT_FULLSCREEN | OPT_MEDIAFIFO | OPT_NOTEAR | OPT_SOUND)
  90. .cmd(DL::DL_DISPLAY)
  91. .cmd(CMD_SWAP)
  92. .execute();
  93. uint32_t writePtr = 0;
  94. int16_t nBytes;
  95. uint32_t t = millis();
  96. uint8_t timeouts;
  97. spiInit(SPI_HALF_SPEED); // Boost SPI speed for video playback
  98. do {
  99. // Write block n
  100. nBytes = (*data_stream)(obj, buf, block_size);
  101. if (nBytes == -1) break;
  102. if (millis() - t > 10) {
  103. ExtUI::yield();
  104. t = millis();
  105. }
  106. CLCD::mem_write_bulk (fifo_start + writePtr, buf, nBytes);
  107. // Wait for FTDI810 to finish playing block n-1
  108. timeouts = 20;
  109. do {
  110. if (millis() - t > 10) {
  111. ExtUI::yield();
  112. t = millis();
  113. timeouts--;
  114. if (timeouts == 0) {
  115. SERIAL_ECHO_MSG("Timeout playing video");
  116. cmd.reset();
  117. goto exit;
  118. }
  119. }
  120. } while (CLCD::mem_read_32(CLCD::REG::MEDIAFIFO_READ) != writePtr);
  121. // Start playing block n
  122. writePtr = (writePtr + nBytes) % fifo_size;
  123. CLCD::mem_write_32(CLCD::REG::MEDIAFIFO_WRITE, writePtr);
  124. } while (nBytes == block_size);
  125. SERIAL_ECHO_MSG("Done playing video");
  126. exit:
  127. spiInit(SPI_SPEED); // Restore default speed
  128. // Since playing media overwrites RAMG, we need to reinitialize
  129. // everything that is stored in RAMG.
  130. cmd.cmd(CMD_DLSTART).execute();
  131. DLCache::init();
  132. StatusScreen::loadBitmaps();
  133. }
  134. #else
  135. UNUSED(obj);
  136. UNUSED(data_stream);
  137. #endif // FTDI_API_LEVEL >= 810
  138. }
  139. #endif // TOUCH_UI_FTDI_EVE