Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 57 additions & 38 deletions test/testffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ static SDL_Window *window;
static SDL_Renderer *renderer;
static SDL_AudioStream *audio;
static SDL_Texture *video_texture;
static AVCodecContext *audio_context;
static AVCodecContext *video_context;
static Uint64 video_start;
static bool nodelay;
static bool software_only;
Expand Down Expand Up @@ -347,7 +349,8 @@ static bool SupportedPixelFormat(enum AVPixelFormat format)
return true;
}
#endif
if (vulkan_context && format == AV_PIX_FMT_VULKAN) {
if (vulkan_context &&
(format == AV_PIX_FMT_VULKAN || format == AV_PIX_FMT_VAAPI || format == AV_PIX_FMT_DRM_PRIME)) {
return true;
}
}
Expand Down Expand Up @@ -497,15 +500,28 @@ static SDL_Colorspace GetFrameColorspace(AVFrame *frame)
SDL_Colorspace colorspace = SDL_COLORSPACE_SRGB;

if (frame && frame->colorspace != AVCOL_SPC_RGB) {
if (frame->colorspace != AVCOL_SPC_UNSPECIFIED ||
video_context->colorspace == AVCOL_SPC_UNSPECIFIED) {
#ifdef DEBUG_COLORSPACE
SDL_Log("Frame colorspace: range: %d, primaries: %d, trc: %d, colorspace: %d, chroma_location: %d", frame->color_range, frame->color_primaries, frame->color_trc, frame->colorspace, frame->chroma_location);
SDL_Log("Frame colorspace: range: %d, primaries: %d, trc: %d, colorspace: %d, chroma_location: %d", frame->color_range, frame->color_primaries, frame->color_trc, frame->colorspace, frame->chroma_location);
#endif
colorspace = SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
frame->color_range,
frame->color_primaries,
frame->color_trc,
frame->colorspace,
frame->chroma_location);
colorspace = SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
frame->color_range,
frame->color_primaries,
frame->color_trc,
frame->colorspace,
frame->chroma_location);
} else if (video_context->colorspace != AVCOL_SPC_UNSPECIFIED) {
#ifdef DEBUG_COLORSPACE
SDL_Log("Video colorspace: range: %d, primaries: %d, trc: %d, colorspace: %d, chroma_location: %d", video_context->color_range, video_context->color_primaries, video_context->color_trc, video_context->colorspace, video_context->chroma_sample_location);
#endif
colorspace = SDL_DEFINE_COLORSPACE(SDL_COLOR_TYPE_YCBCR,
video_context->color_range,
video_context->color_primaries,
video_context->color_trc,
video_context->colorspace,
video_context->chroma_sample_location);
}
}
return colorspace;
}
Expand Down Expand Up @@ -654,9 +670,26 @@ static bool GetTextureForMemoryFrame(AVFrame *frame, SDL_Texture **texture)
return true;
}

static bool GetTextureForVulkanFrame(AVFrame *frame, SDL_Texture **texture)
{
SDL_PropertiesID props;

if (*texture) {
SDL_DestroyTexture(*texture);
}

props = CreateVideoTextureProperties(frame, SDL_PIXELFORMAT_UNKNOWN, SDL_TEXTUREACCESS_STATIC);
*texture = CreateVulkanVideoTexture(vulkan_context, frame, renderer, props);
SDL_DestroyProperties(props);
if (!*texture) {
return false;
}
return true;
}

#ifdef HAVE_EGL

static bool GetNV12TextureForDRMFrame(AVFrame *frame, SDL_Texture **texture)
static bool GetEGLNV12TextureForDRMFrame(AVFrame *frame, SDL_Texture **texture)
{
AVHWFramesContext *frames = (AVHWFramesContext *)(frame->hw_frames_ctx ? frame->hw_frames_ctx->data : NULL);
const AVDRMFrameDescriptor *desc = (const AVDRMFrameDescriptor *)frame->data[0];
Expand Down Expand Up @@ -746,7 +779,7 @@ static bool GetNV12TextureForDRMFrame(AVFrame *frame, SDL_Texture **texture)
return true;
}

static bool GetOESTextureForDRMFrame(AVFrame *frame, SDL_Texture **texture)
static bool GetEGLOESTextureForDRMFrame(AVFrame *frame, SDL_Texture **texture)
{
AVHWFramesContext *frames = (AVHWFramesContext *)(frame->hw_frames_ctx ? frame->hw_frames_ctx->data : NULL);
const AVDRMFrameDescriptor *desc = (const AVDRMFrameDescriptor *)frame->data[0];
Expand Down Expand Up @@ -931,19 +964,24 @@ static bool GetOESTextureForDRMFrame(AVFrame *frame, SDL_Texture **texture)

static bool GetTextureForDRMFrame(AVFrame *frame, SDL_Texture **texture)
{
if (vulkan_context) {
return GetTextureForVulkanFrame(frame, texture);
} else {
#ifdef HAVE_EGL
const AVDRMFrameDescriptor *desc = (const AVDRMFrameDescriptor *)frame->data[0];
const AVDRMFrameDescriptor *desc = (const AVDRMFrameDescriptor *)frame->data[0];

if (desc->nb_layers == 2 &&
desc->layers[0].format == DRM_FORMAT_R8 &&
desc->layers[1].format == DRM_FORMAT_GR88) {
return GetNV12TextureForDRMFrame(frame, texture);
} else {
return GetOESTextureForDRMFrame(frame, texture);
}
if (desc->nb_layers == 2 &&
desc->layers[0].format == DRM_FORMAT_R8 &&
desc->layers[1].format == DRM_FORMAT_GR88) {
return GetEGLNV12TextureForDRMFrame(frame, texture);
} else {
return GetEGLOESTextureForDRMFrame(frame, texture);
}
#else
return false;
SDL_Log("Creating EGL textures is not supported");
return false;
#endif
}
}

static bool GetTextureForVAAPIFrame(AVFrame *frame, SDL_Texture **texture)
Expand Down Expand Up @@ -1029,23 +1067,6 @@ static bool GetTextureForVideoToolboxFrame(AVFrame *frame, SDL_Texture **texture
#endif
}

static bool GetTextureForVulkanFrame(AVFrame *frame, SDL_Texture **texture)
{
SDL_PropertiesID props;

if (*texture) {
SDL_DestroyTexture(*texture);
}

props = CreateVideoTextureProperties(frame, SDL_PIXELFORMAT_UNKNOWN, SDL_TEXTUREACCESS_STATIC);
*texture = CreateVulkanVideoTexture(vulkan_context, frame, renderer, props);
SDL_DestroyProperties(props);
if (!*texture) {
return false;
}
return true;
}

static bool GetTextureForFrame(AVFrame *frame, SDL_Texture **texture)
{
switch (frame->format) {
Expand Down Expand Up @@ -1305,8 +1326,6 @@ int main(int argc, char *argv[])
const char *video_codec_name = NULL;
const AVCodec *audio_codec = NULL;
const AVCodec *video_codec = NULL;
AVCodecContext *audio_context = NULL;
AVCodecContext *video_context = NULL;
AVPacket *pkt = NULL;
AVFrame *frame = NULL;
double first_pts = -1.0;
Expand Down
Loading