Skip to content

Commit

Permalink
Change in accumulated time logic in loopback and also Adding of accum…
Browse files Browse the repository at this point in the history
…ulated time in output json log
  • Loading branch information
sanchay97-dev committed Nov 29, 2024
1 parent 440aa78 commit 4a2b2e0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
33 changes: 16 additions & 17 deletions app/src/main/java/com/facebook/encapp/BufferTranscoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static native int x264Encode(byte[] yuvByteArray, byte[] outputBuffer, in
int encodedequeuinput = 0;
int encodedequeuoutput = 0;
long mLoopback = 0;
long finalAccumulatedTime = 0;

/*Flag indicates dequeue decoded o/p from decoder */
boolean decOutputExtractDone = false;
Expand Down Expand Up @@ -478,7 +479,8 @@ public String start() {
inpPlaneStride = null;
downscaleByteBuffArr = null;
downscalePlaneStride = null;
return String.valueOf(mLoopback);

return "{ \"loopback\" : " + mLoopback + ",\"accumulatedvalue\" : " + finalAccumulatedTime + "}";
}

public void writeToBuffer(@NonNull MediaCodec codec, int index, boolean encoder) {
Expand Down Expand Up @@ -779,7 +781,13 @@ void bufferTranscoding(int trackIndex) throws IOException {

// End of stream reached; perform loopback
lastPresentationTimeUs += clipDurationUs;
accumulatedDurationUs += clipDurationUs;

long loopback_finished = Calendar.getInstance().getTimeInMillis();
long elapsed_time = (loopback_finished - starttime) * 1000;

starttime = loopback_finished;

accumulatedDurationUs += elapsed_time;
// **Note** : Run loopback till it exceeds totalDuration.
// And Don't do accumulatedDurationUs += clipDurationUs;
// Need to test with multiple test in pbtxt.
Expand All @@ -788,22 +796,13 @@ void bufferTranscoding(int trackIndex) throws IOException {
if (accumulatedDurationUs >= totalDurationUs) {
Log.d(TAG, "Reached End");
Log.d(TAG, "accumulatedDurationUs : " + accumulatedDurationUs);
long loopback_finished = Calendar.getInstance().getTimeInMillis();
long elapsed_time = (loopback_finished - starttime) * 1000;
finalAccumulatedTime = accumulatedDurationUs;

Log.d(TAG, "elapsed_time : " + elapsed_time);

if(elapsed_time < totalDurationUs) {
accumulatedDurationUs = elapsed_time;
continue;
}
else {
// End of stream - send EOS flag
mDecoder.queueInputBuffer(inputBufferIndex, 0, 0, 0L,
MediaCodec.BUFFER_FLAG_END_OF_STREAM);
decOutputExtractDone = true;
break;
}
// End of stream - send EOS flag
mDecoder.queueInputBuffer(inputBufferIndex, 0, 0, 0L,
MediaCodec.BUFFER_FLAG_END_OF_STREAM);
decOutputExtractDone = true;
break;

} else {
continue;
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/com/facebook/encapp/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import android.media.MediaCodec;

import org.json.JSONException;
import org.json.JSONObject;

public class MainActivity extends AppCompatActivity {
private final static String TAG = "encapp.main";
Expand Down Expand Up @@ -102,6 +103,7 @@ public class MainActivity extends AppCompatActivity {
int startbattery;
int endbattery;
long mLoopback = 0;
long accumulatedtime = 0;
Encoder coder;
String fullFilename="";
private static List<String> VIDEO_ENCODED_EXTENSIONS = Arrays.asList("mp4", "webm", "mkv");
Expand Down Expand Up @@ -964,10 +966,14 @@ public void run() {
status = coder.start();
boolean status_flag = false;
try {
mLoopback = Long.parseLong(status);
// mLoopback = Long.parseLong(status);
// status_flag = true;
JSONObject response = new JSONObject(status);
status_flag = true;
mLoopback = response.getLong("loopback");
accumulatedtime = response.getLong("accumulatedvalue");
}
catch (NumberFormatException e) {
catch (JSONException e) {
Log.d(TAG, "NumberFormatException Happened : " + e.getMessage());
}
if (status_flag) {
Expand All @@ -993,7 +999,7 @@ public void run() {
stats.setStatus(status);
Log.d(TAG, "Write stats for " + stats.getId() + " to " + fullFilename);
endbattery = getChargeCounter();
stats.LoopbackData(mLoopback);
stats.LoopbackData(mLoopback, accumulatedtime);
stats.BatteryTest(startbattery,endbattery,voltage);
try {
Log.d(TAG, "Write stats for " + stats.getId() + " to " + fullFilename);
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/facebook/encapp/utils/Statistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class Statistics {
final static String TAG = "encapp.statistics";
Expand Down Expand Up @@ -60,6 +61,7 @@ public class Statistics {
int mbatteryDifference;
double mtotalEnergyConsumption;
long mloopbacks = 0;
long finalaccumulated = 0;
double menergy_consumption_per_loopback = 0.0;

private static List<String> MEDIAFORMAT_KEY_STRING_LIST = Arrays.asList(
Expand Down Expand Up @@ -286,8 +288,9 @@ public void BatteryTest(int startbattery,int endbattery,double Voltage) {
}
}

public void LoopbackData(long no_of_loopbacks) {
public void LoopbackData(long no_of_loopbacks, long accumulatedtime) {
mloopbacks = no_of_loopbacks;
finalaccumulated = accumulatedtime;
}

public void setEncoderMediaFormat(MediaFormat format) {
Expand Down Expand Up @@ -528,6 +531,8 @@ public void writeJSON(Writer writer) throws IOException, JSONException {
JSONObject loopbackData = new JSONObject();
loopbackData.put("Number_of_Loopbacks", mloopbacks);
loopbackData.put("Energy_Consumption_per_loopback", menergy_consumption_per_loopback);
String accumulatedInMins = String.valueOf(TimeUnit.MINUTES.convert(finalaccumulated, TimeUnit.MICROSECONDS));
loopbackData.put("Total_time_taken_to_finish_transcoding", accumulatedInMins+" mins");
json.put("Loopback_data", loopbackData);

// GPU info
Expand Down

0 comments on commit 4a2b2e0

Please sign in to comment.