Skip to content

Commit

Permalink
-Add Execute method to pipeline.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-gomez-windhover committed Dec 11, 2024
1 parent 0a99db0 commit 37ab038
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 9 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/windhoverlabs/com/video/FilterGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ public void SetConfig(MMC_FilterGraphCfg_t filterGraphCfg) {
// TODO Auto-generated method stub

}

public static void Initialize() {
// TODO Auto-generated method stub

}

public static void Start() {
// TODO Auto-generated method stub

}

public void Execute() {
// TODO Auto-generated method stub

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ public static class MMC_InputPipelineCfg_t {
MMC_CustomFrameProcessorCfg_t CustomFrameProcessorCfg;
String FilterBufferSrcArgs;
}
;

// Additional structures can be added here following the same pattern
}
146 changes: 138 additions & 8 deletions src/main/java/com/windhoverlabs/com/video/Pipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@

import static org.bytedeco.ffmpeg.global.avutil.*;

import org.bytedeco.ffmpeg.avcodec.AVPacket;
import org.bytedeco.ffmpeg.avformat.AVStream;
import org.bytedeco.ffmpeg.avutil.*;
import org.bytedeco.ffmpeg.global.avcodec;

public class Pipeline {
public class Pipeline extends ComponentBase {

private MMC_PipelineCfg config;
private AVBufferRef hwAccelDeviceContext;
// TODO:It might make more sense to change these arrays to ArrayList(s)
private InputPipeline[] inputPipelines = new InputPipeline[MAX_INPUT_PIPELINES];
private FilterGraph filterGraph = new FilterGraph();
private OutputPipeline[] outputPipelines = new OutputPipeline[MAX_OUTPUT_PIPELINES];

private int ChannelID = 0xFFFFFFFF;
private TState State;
private AVFrame Frame;
private AVPacket Packet;

public Pipeline() {
// TODO: Auto-generated constructor stub
}
Expand Down Expand Up @@ -52,18 +61,139 @@ public void initializeHWAccel() {
0);

if (avRC < 0) {
reportAVError("av_hwdevice_ctx_create failed", avRC);
ReportAVError(
"CPipeline::InitializeHardware",
"av_hwdevice_ctx_create",
avRC,
Thread.currentThread().getStackTrace()[0].getLineNumber());
}
}

private void reportAVError(String message, int errorCode) {
// Log or handle the error based on the errorCode
System.err.println(message + ": " + errorCode);
public EReturnCode Initialize() {
EReturnCode rc = EReturnCode.OK;

super.Initialize();

Frame = av_frame_alloc();
Packet = avcodec.av_packet_alloc();

// First set the pipeline IDs, so error reporting will be correct.
for (int i = 0; i < MAX_INPUT_PIPELINES; i++) {
inputPipelines[i].SetPipelineID(i);
}

for (int i = 0; i < MAX_OUTPUT_PIPELINES; i++) {
outputPipelines[i].SetPipelineID(i);
}

initializeHWAccel();

if (!config.PacketLevelRemux) {
FilterGraph.Initialize();
}

// Now initialize the pipelines.
for (int i = 0; i < MAX_INPUT_PIPELINES; i++) {
inputPipelines[i].Initialize(filterGraph, hwAccelDeviceContext);
}

for (int i = 0; i < MAX_OUTPUT_PIPELINES; i++) {
AVStream inputStream = inputPipelines[i].GetStream();

outputPipelines[i].Initialize(
config.PacketLevelRemux, filterGraph, hwAccelDeviceContext, inputStream);
}

if (!config.PacketLevelRemux) {
FilterGraph.Start();
if (rc != EReturnCode.OK) {
rc = EReturnCode.FAILED_INITIALIZATION;
return rc;
}
}

State = TState.ACTIVE;

return rc;
}

public TState GetState() {
return State;
}

EReturnCode Restart(int PipelineID) {
EReturnCode rc = EReturnCode.OK;

rc = inputPipelines[PipelineID].Restart();

if (EReturnCode.OK == rc) {
rc = outputPipelines[PipelineID].restart();
}

return rc;
}

enum EReturnCode {
OK,
ERROR;
EReturnCode Execute() {
EReturnCode rc = EReturnCode.OK;

if (TState.ACTIVE == State) {
for (int i = 0; i < MAX_INPUT_PIPELINES; ++i) {
if (config.PacketLevelRemux) {

rc = inputPipelines[i].ReadPacket(Packet);
if (EReturnCode.OK_EOF == rc) {
Restart(i);
continue;
}

if (rc != EReturnCode.OK) {
/* TODO */
State = TState.INACTIVE;
// goto end_of_function;
}

rc = outputPipelines[i].SendPacket(Packet);
if (rc != EReturnCode.OK) {
/* TODO */
State = TState.INACTIVE;
// goto end_of_function;
}
} else {
rc = inputPipelines[i].ReadFrame();
if (EReturnCode.OK_EOF == rc) {
Restart(i);
} else if (rc != EReturnCode.OK) {
/* TODO */
State = TState.INACTIVE;
// goto end_of_function;
}

rc = outputPipelines[i].SendFrame();
while (rc == EReturnCode.OK_QUEUE_EMPTY) {
rc = outputPipelines[i].SendFrame();
}
if (rc != EReturnCode.OK) {
/* TODO */
State = TState.INACTIVE;
// goto end_of_function;
}
}

// filterGraph.SetFrame(i, inputPipelines[i].GetFrame());
}

// filterGraph.Execute();
//
// for(int i = 0; i < MAX_OUTPUT_PIPELINES; ++i)
// {
// OutputPipeline[i].SetFrame(FilterGraph.GetFrame(i));
// OutputPipeline[i].Execute();
// }
}

// end_of_function:

return rc;
}

// Constants (replace with actual values)
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/windhoverlabs/com/video/TState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.windhoverlabs.com.video;

public enum TState {
UNUSED,
INACTIVE,
ACTIVE;
}

0 comments on commit 37ab038

Please sign in to comment.