Skip to content

Commit

Permalink
Update FFMpeg to mainstream 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Oct 7, 2024
1 parent fd15a45 commit b25f868
Show file tree
Hide file tree
Showing 140 changed files with 33,979 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
- name: Remove enet
run: dkp-pacman --noconfirm -R switch-enet

- name: Remove ffmpeg
run: dkp-pacman --noconfirm -R switch-ffmpeg

- name: Run cmake
continue-on-error: true
run: cmake -B build/switch -DPLATFORM_SWITCH=ON
Expand Down
33 changes: 23 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${EXTERN_PATH}/cmake")
project(Moonlight)
set(VERSION_MAJOR "1")
set(VERSION_MINOR "2")
set(VERSION_ALTER "1")
set(VERSION_ALTER "2")
set(VERSION_BUILD "1")
set(PACKAGE_NAME "ru.xitrix.Moonlight")
set(PSN_TITLE_ID "MNTL00000")
Expand Down Expand Up @@ -201,7 +201,7 @@ elseif (PLATFORM_SWITCH)
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/resources/font
COMMAND ${NX_ELF2NRO_EXE} ${PROJECT_NAME}.elf ${PROJECT_NAME}.nro --icon=${PROJECT_ICON} --nacp=${PROJECT_NAME}.nacp --romfsdir=${CMAKE_BINARY_DIR}/resources
)
list(APPEND APP_PLATFORM_LIB swresample dav1d z)
list(APPEND APP_PLATFORM_LIB dav1d z)
elseif (PLATFORM_ANDROID)
list(APPEND APP_PLATFORM_LIB android)
target_link_libraries(${PROJECT_NAME} PRIVATE
Expand Down Expand Up @@ -284,17 +284,30 @@ find_package(PNG REQUIRED)
find_library(OPUS_LIBRARY opus)
message("opus: ${OPUS_LIBRARY}")

find_library(AVCODEC_LIBRARY avcodec)
message("avcodec: ${AVCODEC_LIBRARY}")
if(PLATFORM_SWITCH)
target_link_libraries(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/lib/switch/libavcodec.a
${CMAKE_CURRENT_SOURCE_DIR}/lib/switch/libavformat.a
${CMAKE_CURRENT_SOURCE_DIR}/lib/switch/libavutil.a
${CMAKE_CURRENT_SOURCE_DIR}/lib/switch/libswresample.a
)

find_library(AVFORMAT_LIBRARY avformat)
message("avformat: ${AVFORMAT_LIBRARY}")
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/lib/switch/include
)
else()
find_library(AVCODEC_LIBRARY avcodec)
message("avcodec: ${AVCODEC_LIBRARY}")

find_library(AVFORMAT_LIBRARY avformat)
message("avformat: ${AVFORMAT_LIBRARY}")

find_library(AVUTIL_LIBRARY avutil)
message("avutil: ${AVUTIL_LIBRARY}")
find_library(AVUTIL_LIBRARY avutil)
message("avutil: ${AVUTIL_LIBRARY}")

find_library(SWRESAMPLE_LIBRARY swresample)
message("swresample: ${SWRESAMPLE_LIBRARY}")
find_library(SWRESAMPLE_LIBRARY swresample)
message("swresample: ${SWRESAMPLE_LIBRARY}")
endif ()

# Recompiled CURL with Mbedtls support for Switch
if(PLATFORM_SWITCH)
Expand Down
9 changes: 5 additions & 4 deletions app/src/streaming/ffmpeg/FFmpegVideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
int redraw_rate, void* context, int dr_flags) {
m_stream_fps = redraw_rate;

brls::Logger::debug("FFMpeg's AVCodec version: {}.{}.{}", AV_VERSION_MAJOR(avcodec_version()), AV_VERSION_MINOR(avcodec_version()), AV_VERSION_MICRO(avcodec_version()));
brls::Logger::info(
"FFmpeg: Setup with format: {}, width: {}, height: {}, fps: {}",
video_format == VIDEO_FORMAT_H264 ? "H264" : "HEVC", width, height,
Expand Down Expand Up @@ -86,7 +87,7 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
m_decoder_context->height = height;
#ifdef __SWITCH__
#ifdef BOREALIS_USE_DEKO3D
m_decoder_context->pix_fmt = AV_PIX_FMT_TX1;
m_decoder_context->pix_fmt = AV_PIX_FMT_NVTEGRA;
#else
m_decoder_context->pix_fmt = AV_PIX_FMT_NV12;
#endif
Expand All @@ -109,7 +110,7 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
}

#if defined(__SWITCH__) && defined(BOREALIS_USE_DEKO3D)
m_frames[i]->format = AV_PIX_FMT_TX1;
m_frames[i]->format = AV_PIX_FMT_NVTEGRA;
#elif defined(PLATFORM_ANDROID)
m_frames[i]->format = AV_PIX_FMT_MEDIACODEC;
#else
Expand All @@ -118,7 +119,7 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
m_frames[i]->width = width;
m_frames[i]->height = height;

// Need to allign Switch frame to 256, need to de reviewed
// Need to align Switch frame to 256, need to de reviewed
#if defined(__SWITCH__) && !defined(BOREALIS_USE_DEKO3D)
int err = av_frame_get_buffer(m_frames[i], 256);
if (err < 0) {
Expand Down Expand Up @@ -146,7 +147,7 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,

if (Settings::instance().use_hw_decoding()) {
#if defined(__SWITCH__)
if ((err = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_TX1, NULL, NULL, 0)) < 0) {
if ((err = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_NVTEGRA, NULL, NULL, 0)) < 0) {
brls::Logger::error("FFmpeg: Error initializing hardware decoder - {}", err);
return -1;
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/streaming/video/deko3d/DKVideoRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <borealis/platforms/switch/switch_platform.hpp>

#include <libavcodec/avcodec.h>
#include <libavutil/hwcontext_tx1.h>
#include <libavutil/hwcontext_nvtegra.h>
#include <libavutil/imgutils.h>

#include <array>
Expand Down Expand Up @@ -85,7 +85,7 @@ void DKVideoRenderer::checkAndInitialize(int width, int height, AVFrame* frame)
brls::Logger::debug("{}: Luma texture ID {}", __PRETTY_FUNCTION__, lumaTextureId);
brls::Logger::debug("{}: Chroma texture ID {}", __PRETTY_FUNCTION__, chromaTextureId);

AVTX1Map *map = ff_tx1_frame_get_fbuf_map(frame);
AVNVTegraMap *map = av_nvtegra_frame_get_fbuf_map(frame);
brls::Logger::info("{}: Map size: {} | {} | {} | {}", __PRETTY_FUNCTION__, map->map.handle, map->map.has_init, map->map.cpu_addr, map->map.size);

dk::ImageLayoutMaker { dev }
Expand All @@ -102,9 +102,9 @@ void DKVideoRenderer::checkAndInitialize(int width, int height, AVFrame* frame)
.setFlags(DkImageFlags_UsageLoadStore | DkImageFlags_Usage2DEngine | DkImageFlags_UsageVideo)
.initialize(chromaMappingLayout);

mappingMemblock = dk::MemBlockMaker { dev, ff_tx1_map_get_size(map) }
mappingMemblock = dk::MemBlockMaker { dev, av_nvtegra_map_get_size(map) }
.setFlags(DkMemBlockFlags_CpuUncached | DkMemBlockFlags_GpuCached | DkMemBlockFlags_Image)
.setStorage(ff_tx1_map_get_addr(map))
.setStorage(av_nvtegra_map_get_addr(map))
.create();

luma.initialize(lumaMappingLayout, mappingMemblock, 0);
Expand Down
36 changes: 36 additions & 0 deletions lib/switch/include/libavcodec/ac3_parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* AC-3 parser prototypes
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef AVCODEC_AC3_PARSER_H
#define AVCODEC_AC3_PARSER_H

#include <stddef.h>
#include <stdint.h>

/**
* Extract the bitstream ID and the frame size from AC-3 data.
*/
int av_ac3_parse_header(const uint8_t *buf, size_t size,
uint8_t *bitstream_id, uint16_t *frame_size);


#endif /* AVCODEC_AC3_PARSER_H */
37 changes: 37 additions & 0 deletions lib/switch/include/libavcodec/adts_parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef AVCODEC_ADTS_PARSER_H
#define AVCODEC_ADTS_PARSER_H

#include <stddef.h>
#include <stdint.h>

#define AV_AAC_ADTS_HEADER_SIZE 7

/**
* Extract the number of samples and frames from AAC data.
* @param[in] buf pointer to AAC data buffer
* @param[out] samples Pointer to where number of samples is written
* @param[out] frames Pointer to where number of frames is written
* @return Returns 0 on success, error code on failure.
*/
int av_adts_header_parse(const uint8_t *buf, uint32_t *samples,
uint8_t *frames);

#endif /* AVCODEC_ADTS_PARSER_H */
Loading

0 comments on commit b25f868

Please sign in to comment.