Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,6 @@ $RECYCLE.BIN/

# Mac crap
.DS_Store

# VS Code
.vscode/
1 change: 1 addition & 0 deletions Motion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ include(${CMAKE_SOURCE_DIR}/cmake/Config.cmake)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
set(CMAKE_CXX_STANDARD 14)

# add the Motion header path
include_directories(${CMAKE_SOURCE_DIR}/include)
Expand Down
42 changes: 25 additions & 17 deletions Motion/src/Motion/DataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern "C"
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
#include <libavutil/imgutils.h>
#include <libavutil/opt.h>
}

Expand All @@ -34,7 +35,7 @@ namespace
if (!picture)
return nullptr;

int size = avpicture_get_size(SelectedPixelFormat, Width, Height);
int size = av_image_get_buffer_size(SelectedPixelFormat, Width, Height, 0);

PictureBuffer = (uint8_t*)av_malloc(size);

Expand All @@ -44,8 +45,8 @@ namespace
return nullptr;
}

avpicture_fill((AVPicture*)picture, PictureBuffer, SelectedPixelFormat, Width, Height);

int ret = av_image_alloc(picture->data, picture->linesize, Width, Height, SelectedPixelFormat, 1);
return picture;
}

Expand Down Expand Up @@ -116,7 +117,6 @@ namespace mt
m_videoPlaybacks(),
m_audioPlaybacks()
{
av_register_all();
}

DataSource::~DataSource()
Expand Down Expand Up @@ -218,7 +218,7 @@ namespace mt

for (unsigned int i = 0; i < m_data->formatContext->nb_streams; i++)
{
switch (m_data->formatContext->streams[i]->codec->codec_type)
switch (m_data->formatContext->streams[i]->codecpar->codec_type)
{
case AVMEDIA_TYPE_VIDEO:
if (m_data->videoStreamID == -1 && EnableVideo)
Expand All @@ -237,7 +237,8 @@ namespace mt

if (HasVideo())
{
m_data->videoContext = m_data->formatContext->streams[m_data->videoStreamID]->codec;
m_data->videoContext = avcodec_alloc_context3(nullptr);
avcodec_parameters_to_context(m_data->videoContext, m_data->formatContext->streams[m_data->videoStreamID]->codecpar);

if (!m_data->videoContext)
{
Expand All @@ -246,7 +247,8 @@ namespace mt
}
else
{
m_data->videoCodec = avcodec_find_decoder(m_data->videoContext->codec_id);
const AVCodec* codec = avcodec_find_decoder(m_data->videoContext->codec_id);
m_data->videoCodec = const_cast<AVCodec*>(codec);

if (!m_data->videoCodec)
{
Expand Down Expand Up @@ -284,7 +286,8 @@ namespace mt

if (HasAudio())
{
m_data->audioContext = m_data->formatContext->streams[m_data->audioStreamID]->codec;
const AVCodec* const_codec = avcodec_find_decoder(m_data->formatContext->streams[m_data->audioStreamID]->codecpar->codec_id);
m_data->audioCodec = const_cast<AVCodec*>(const_codec);

if (!m_data->audioContext)
{
Expand All @@ -293,7 +296,8 @@ namespace mt
}
else
{
m_data->audioCodec = avcodec_find_decoder(m_data->audioContext->codec_id);
const AVCodec* const_codec = avcodec_find_decoder(m_data->audioContext->codec_id);
m_data->audioCodec = const_cast<AVCodec*>(const_codec);

if (!m_data->audioCodec)
{
Expand Down Expand Up @@ -636,11 +640,9 @@ namespace mt
{
if (packet->stream_index == m_data->videoStreamID)
{
int decoderesult = 0;

if (avcodec_decode_video2(m_data->videoContext, m_data->videoRawFrame, &decoderesult, packet) >= 0)
if (avcodec_send_packet(m_data->videoContext, packet) == 0)
{
if (decoderesult)
while (avcodec_receive_frame(m_data->videoContext, m_data->videoRawFrame) == 0)
{
if (sws_scale(m_data->videoSWContext, m_data->videoRawFrame->data, m_data->videoRawFrame->linesize, 0, m_data->videoContext->height, m_data->videoRGBAFrame->data, m_data->videoRGBAFrame->linesize))
{
Expand All @@ -667,11 +669,16 @@ namespace mt
{
int decoderesult = 0;

if (avcodec_decode_audio4(m_data->audioContext, m_data->audioRawBuffer, &decoderesult, packet) > 0)
if (avcodec_send_packet(m_data->audioContext, packet) == 0)
{
if (decoderesult)
AVFrame *frame = av_frame_alloc();
if (frame == NULL)
{
// handle error
}
if (avcodec_receive_frame(m_data->audioContext, frame) == 0)
{
int convertlength = swr_convert(m_data->audioSWContext, &m_data->audioPCMBuffer, m_data->audioRawBuffer->nb_samples, (const uint8_t**)m_data->audioRawBuffer->extended_data, m_data->audioRawBuffer->nb_samples);
int convertlength = swr_convert(m_data->audioSWContext, &m_data->audioPCMBuffer, m_data->audioRawBuffer->nb_samples, (const uint8_t**)frame->extended_data, frame->nb_samples);

if (convertlength > 0)
{
Expand All @@ -692,18 +699,19 @@ namespace mt
isfull = IsFull();
}
}
av_frame_free(&frame);
}
}

av_free_packet(packet);
av_packet_unref(packet);
av_free(packet);
}
else
{
m_PlayingToEOF = true;
validpacket = true;

av_free_packet(packet);
av_packet_unref(packet);
av_free(packet);
}
}
Expand Down
17 changes: 6 additions & 11 deletions MotionNET/MotionNET.SFML/Config.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using System.Runtime.InteropServices;

namespace MotionNET.SFML
namespace MotionNET.SFML;

internal class Config
{
internal static class Config
{
#if DEBUG
internal const string Motion_DLL = "Motion-d";
internal const CallingConvention Motion_Call = CallingConvention.Cdecl;
#else
internal const string Motion_DLL = "Motion";
internal const CallingConvention Motion_Call = CallingConvention.Cdecl;
#endif
}
internal const string MotionDll = "Motion";
internal const CallingConvention MotionCall = CallingConvention.Cdecl;
}

87 changes: 10 additions & 77 deletions MotionNET/MotionNET.SFML/MotionNET.SFML.csproj
Original file line number Diff line number Diff line change
@@ -1,84 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DCF8D510-B161-4218-93C3-EF39558E3DF5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MotionNET.SFML</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>MotionNET.SFML</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
<RootNamespace>MotionNET.SFML</RootNamespace>
<OutputType>Library</OutputType>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Reference Include="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
<Reference Include="sfml-graphics" />
<Reference Include="sfml-system" />
<Reference Include="sfml-window" />
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SFMLAudioPlayback.cs" />
<Compile Include="SFMLVideoPlayback.cs" />
<PackageReference Include="SFML.Net" Version="2.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MotionNET\MotionNET.csproj">
<Project>{a947192e-0ddb-4a4f-a90d-ed5491e826a9}</Project>
<Name>MotionNET</Name>
</ProjectReference>
<ProjectReference Include="..\MotionNET\MotionNET.csproj" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
36 changes: 0 additions & 36 deletions MotionNET/MotionNET.SFML/Properties/AssemblyInfo.cs

This file was deleted.

Loading