Skip to content

Commit

Permalink
Set matching resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
skilurius committed Aug 30, 2024
1 parent eac2f17 commit 9753743
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 9 additions & 0 deletions app/src/main/java/com/openipc/pixelpilot/VideoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.documentfile.provider.DocumentFile;

import com.github.mikephil.charting.charts.PieChart;
Expand Down Expand Up @@ -124,6 +125,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityVideoBinding.inflate(getLayoutInflater());
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);

// Init wfb ng.
Expand Down Expand Up @@ -494,6 +496,13 @@ public void onChannelSettingChanged(int channel) {
public void onVideoRatioChanged(final int videoW, final int videoH) {
lastVideoW = videoW;
lastVideoH = videoH;

Log.d(TAG, "Set resolution: " + videoW + "x" + videoH);
View mSurface = findViewById(R.id.mainVideo);
ConstraintLayout.LayoutParams params =
(ConstraintLayout.LayoutParams) mSurface.getLayoutParams();
params.dimensionRatio = videoW + ":" + videoH;
runOnUiThread(() -> mSurface.setLayoutParams(params));
}

@Override
Expand Down
4 changes: 1 addition & 3 deletions app/videonative/src/main/cpp/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,14 @@ void VideoDecoder::checkOutputLoop() {
BUFFER_TIMEOUT_US);
if (index >= 0) {
const auto now = steady_clock::now();
const int64_t nowNS = (int64_t) duration_cast<nanoseconds>(
now.time_since_epoch()).count();
const int64_t nowUS = (int64_t) duration_cast<microseconds>(
now.time_since_epoch()).count();
//the timestamp for releasing the buffer is in NS, just release as fast as possible (e.g. now)
//https://android.googlesource.com/platform/frameworks/av/+/master/media/ndk/NdkMediaCodec.cpp
//-> renderOutputBufferAndRelease which is in https://android.googlesource.com/platform/frameworks/av/+/3fdb405/media/libstagefright/MediaCodec.cpp
//-> Message kWhatReleaseOutputBuffer -> onReleaseOutputBuffer
// also https://android.googlesource.com/platform/frameworks/native/+/5c1139f/libs/gui/SurfaceTexture.cpp
AMediaCodec_releaseOutputBufferAtTime(decoder.codec, (size_t) index, nowNS);
AMediaCodec_releaseOutputBuffer(decoder.codec, (size_t) index, true);
//but the presentationTime is in US
decodingTime.add(std::chrono::microseconds(nowUS - info.presentationTimeUs));
nDecodedFrames.add(1);
Expand Down

0 comments on commit 9753743

Please sign in to comment.