Skip to content

Commit

Permalink
Duplicate decoding, multipacket.
Browse files Browse the repository at this point in the history
When duplicate bits don't agree, use the stronger candidate.
Return number of such mismatches to Android to use as confidence.
  • Loading branch information
revan committed Mar 24, 2016
1 parent 6f38d9e commit 9a30909
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 242 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -73,3 +73,4 @@ app/src/main/libs/armeabi-v7a/libndk1.so
matlab/*.avi
*.nes
*.idea/
*.m~
11 changes: 7 additions & 4 deletions app/src/main/java/com/android/visualmimo/MainActivity.java
Expand Up @@ -147,12 +147,14 @@ public void onQCARUpdate(State state) {
if (recordingMode)
frameCounter++;

onQCARUpdate(state, ((frameCounter % 10 == 0) && recordingMode)
|| (benchingInProgress && !idleBenchMode));
boolean shouldTakePicture = ((frameCounter % 20 == 0) && recordingMode)
|| (benchingInProgress && !idleBenchMode);
// System.out.println("shouldTakePicture: " + shouldTakePicture);
onQCARUpdate(state, shouldTakePicture);

if (MessageCache.getInstance().isReady()) {
saveCount = 0;
recordingMode = false;
System.out.println("Stopping recording mode.");
}
}

Expand All @@ -162,12 +164,13 @@ public boolean onTouchEvent(MotionEvent event) {
}

private void handleSaveButton() {
System.out.println("Save button pressed.");
// enable recording mode after delay
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
recordingMode = true;

System.out.println("Starting recording mode.");
}
}, 1000);
saveCount = 0;
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/android/visualmimo/MessageUtils.java
Expand Up @@ -14,7 +14,10 @@ public static void printGrid(boolean[] pattern, PrintStream out) {
if ((i == 0 && (j == 0 || j == 9)) || (i == 7 && (j == 0 || j == 9))) {
out.print("S ");
} else {
out.print(pattern[k++] ? "X " : ". ");
if (k < pattern.length)
out.print(pattern[k++] ? "X " : ". ");
else
out.print(" ");
}
}
out.println();
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/android/visualmimo/NDKResult.java
Expand Up @@ -6,10 +6,12 @@
*/
public class NDKResult {
public int index;
public int mismatches;
public boolean[] message;

public NDKResult(int index, boolean[] message) {
public NDKResult(int index, int mismatches, boolean[] message) {
this.index = index;
this.mismatches = mismatches;
this.message = message;
}
}
Expand Up @@ -135,8 +135,9 @@ protected void onQCARUpdate(State state, boolean takePicture){
// }).start();

if (takePicture) {
saveCount++;
// saveCount++;
if (saveCount <= NUM_SAVES) {
System.out.println("Processing frames");
FrameProcessing.processFrames(
cache,
this,
Expand Down
154 changes: 0 additions & 154 deletions app/src/main/java/com/android/visualmimo/persistence/FrameOps.java

This file was deleted.

Expand Up @@ -2,9 +2,6 @@

import com.android.visualmimo.NDKResult;

import java.util.ArrayList;
import java.util.concurrent.LinkedBlockingDeque;

/**
* Singleton which builds up a message across multiple shots.
* @author revan
Expand All @@ -15,15 +12,12 @@ public class MessageCache {
* A hardcoded number of messages.
* TODO: switch to some known "start" pattern to support variable length.
*/
public static final int NUM_MESSAGES = 9;

// private int expectingIndex = 0;
public static final int NUM_MESSAGES = 4;
public static final int MESSAGE_BITS = 4 * 7;
private int size = 0;


// private ArrayList<NDKResult> messages = new ArrayList<NDKResult>(NUM_MESSAGES);
private NDKResult[] messages = new NDKResult[NUM_MESSAGES];
/** Threadsafe, since we access it from the threaded NDK callback. */
// private LinkedBlockingDeque<NDKResult> messages = new LinkedBlockingDeque<NDKResult>();
private final NDKResult[] messages = new NDKResult[NUM_MESSAGES];

private static MessageCache singleton;
private MessageCache() {
Expand All @@ -46,30 +40,42 @@ public static MessageCache getInstance() {
*/
public boolean addMessage(NDKResult result) {
synchronized (messages) {
// if (expectingIndex != result.index) {
// System.err.println("Was expecting index " + expectingIndex + " but got index "
// + result.index + ". Dropping.");
// return false;
// }
if (messages[result.index] != null) {
System.err.println("Duplicate index " + result.index + ", dropping.");
return false;
}

if (isReady()) {
System.err.println("Message cache already ready. Dropping.");
// TODO: try setting high bits to 0
return false;
}

if (result.mismatches > MESSAGE_BITS) {
System.err.println("Way too many mismatches. Dropping.");
return false;
}

// expectingIndex++;
if (result.index >= NUM_MESSAGES) {
System.err.println("Index too large: " + result.index);
return false;
}

if (messages[result.index] == null) {
this.size++;
} else {
if (messages[result.index].mismatches > result.mismatches) {
System.err.println("Duplicate index " + result.index + ", keeping new result.");
} else {
System.err.println("Duplicate index " + result.index + ", keeping old result.");
return false;
}
}

messages[result.index] = result;

return true;
}
}

/** Returns true if all expected messages have been collected. */
public boolean isReady() {
// return NUM_MESSAGES <= messages.size();
for (NDKResult r : messages) {
if (r == null)
return false;
Expand All @@ -79,24 +85,26 @@ public boolean isReady() {

/** Spits out total contents of list. */
public boolean[] assemblePattern() {
if (messages.length == 0) {
if (this.size == 0) {
return new boolean[0];
}

boolean[] pattern = new boolean[messages.length * 21];
boolean[] pattern = new boolean[this.size * MESSAGE_BITS];

int pos = 0;
for (NDKResult result : messages) {
System.arraycopy(result.message, 0, pattern, pos, 21);
pos += 21;
if (result != null) {
System.arraycopy(result.message, 0, pattern, pos, MESSAGE_BITS);
pos += MESSAGE_BITS;
}
}

return pattern;
}

/** Returns number of accepted messages in cache. */
public int size() {
return messages.length;
return this.size;
}

}

0 comments on commit 9a30909

Please sign in to comment.