From f6c4cc8a5f35bb7e67d1f7c7cb1d15774724a4cc Mon Sep 17 00:00:00 2001 From: Denny Sheirer Date: Sat, 10 Feb 2024 03:40:57 -0500 Subject: [PATCH] 1810 P25 Voice frame list concurrent modification error. Added synchronized to method to deconflict when the audio module or the binary frame recorder can access the message and not step on each other. Issue was noted in the phase 2 module, but update the phase 1 module as well to protect against the issue. (#1833) Co-authored-by: Dennis Sheirer --- .../p25/phase1/message/ldu/LDUMessage.java | 64 +++++++++++-------- .../p25/phase2/timeslot/Voice2Timeslot.java | 32 ++++------ .../p25/phase2/timeslot/Voice4Timeslot.java | 33 ++++------ 3 files changed, 64 insertions(+), 65 deletions(-) diff --git a/src/main/java/io/github/dsheirer/module/decode/p25/phase1/message/ldu/LDUMessage.java b/src/main/java/io/github/dsheirer/module/decode/p25/phase1/message/ldu/LDUMessage.java index 1ff5d703..b1168be9 100644 --- a/src/main/java/io/github/dsheirer/module/decode/p25/phase1/message/ldu/LDUMessage.java +++ b/src/main/java/io/github/dsheirer/module/decode/p25/phase1/message/ldu/LDUMessage.java @@ -1,7 +1,6 @@ /* - * ****************************************************************************** - * sdrtrunk - * Copyright (C) 2014-2019 Dennis Sheirer + * ***************************************************************************** + * Copyright (C) 2014-2024 Dennis Sheirer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,23 +14,21 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see - * ***************************************************************************** + * **************************************************************************** */ package io.github.dsheirer.module.decode.p25.phase1.message.ldu; import io.github.dsheirer.bits.CorrectedBinaryMessage; import io.github.dsheirer.module.decode.p25.phase1.message.P25Message; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.ArrayList; import java.util.List; +/** + * LDU voice frame + */ public abstract class LDUMessage extends P25Message { - private final static Logger mLog = LoggerFactory.getLogger(LDUMessage.class); - public static final int IMBE_FRAME_1 = 0; public static final int IMBE_FRAME_2 = 144; public static final int IMBE_FRAME_3 = 328; @@ -41,10 +38,16 @@ public abstract class LDUMessage extends P25Message public static final int IMBE_FRAME_7 = 1064; public static final int IMBE_FRAME_8 = 1248; public static final int IMBE_FRAME_9 = 1424; + public static final int[] LOW_SPEED_DATA = {1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1408, 1409, 1410, 1411, + 1412, 1413, 1414, 1415}; + private List mIMBIFrames; - public static final int[] LOW_SPEED_DATA = {1392, 1393, 1394, 1395, 1396, 1397, - 1398, 1399, 1408, 1409, 1410, 1411, 1412, 1413, 1414, 1415}; - + /** + * Constructs an instance + * @param message with data + * @param nac code + * @param timestamp for the message + */ public LDUMessage(CorrectedBinaryMessage message, int nac, long timestamp) { super(message, nac, timestamp); @@ -58,6 +61,10 @@ public abstract class LDUMessage extends P25Message return getMessage().getHex(LOW_SPEED_DATA, 4); } + /** + * Base message used by subclass implementations. + * @return base message + */ public String getMessageStub() { StringBuilder sb = new StringBuilder(); @@ -70,24 +77,25 @@ public abstract class LDUMessage extends P25Message } /** - * Returns a 162 byte array containing 9 IMBE voice frames of 18-bytes - * (144-bits) each. Each frame is intact as transmitted and requires - * deinterleaving, error correction, derandomizing, etc. + * Returns a 162 byte array containing 9 IMBE voice frames of 18-bytes* (144-bits) each. Each frame is intact as + * transmitted and requires deinterleaving, error correction, derandomizing, etc. */ - public List getIMBEFrames() + public synchronized List getIMBEFrames() { - List frames = new ArrayList(); + if(mIMBIFrames == null) + { + mIMBIFrames = new ArrayList<>(); + mIMBIFrames.add(getMessage().get(IMBE_FRAME_1, IMBE_FRAME_1 + 144).toByteArray()); + mIMBIFrames.add(getMessage().get(IMBE_FRAME_2, IMBE_FRAME_2 + 144).toByteArray()); + mIMBIFrames.add(getMessage().get(IMBE_FRAME_3, IMBE_FRAME_3 + 144).toByteArray()); + mIMBIFrames.add(getMessage().get(IMBE_FRAME_4, IMBE_FRAME_4 + 144).toByteArray()); + mIMBIFrames.add(getMessage().get(IMBE_FRAME_5, IMBE_FRAME_5 + 144).toByteArray()); + mIMBIFrames.add(getMessage().get(IMBE_FRAME_6, IMBE_FRAME_6 + 144).toByteArray()); + mIMBIFrames.add(getMessage().get(IMBE_FRAME_7, IMBE_FRAME_7 + 144).toByteArray()); + mIMBIFrames.add(getMessage().get(IMBE_FRAME_8, IMBE_FRAME_8 + 144).toByteArray()); + mIMBIFrames.add(getMessage().get(IMBE_FRAME_9, IMBE_FRAME_9 + 144).toByteArray()); + } - frames.add(getMessage().get(IMBE_FRAME_1, IMBE_FRAME_1 + 144).toByteArray()); - frames.add(getMessage().get(IMBE_FRAME_2, IMBE_FRAME_2 + 144).toByteArray()); - frames.add(getMessage().get(IMBE_FRAME_3, IMBE_FRAME_3 + 144).toByteArray()); - frames.add(getMessage().get(IMBE_FRAME_4, IMBE_FRAME_4 + 144).toByteArray()); - frames.add(getMessage().get(IMBE_FRAME_5, IMBE_FRAME_5 + 144).toByteArray()); - frames.add(getMessage().get(IMBE_FRAME_6, IMBE_FRAME_6 + 144).toByteArray()); - frames.add(getMessage().get(IMBE_FRAME_7, IMBE_FRAME_7 + 144).toByteArray()); - frames.add(getMessage().get(IMBE_FRAME_8, IMBE_FRAME_8 + 144).toByteArray()); - frames.add(getMessage().get(IMBE_FRAME_9, IMBE_FRAME_9 + 144).toByteArray()); - - return frames; + return mIMBIFrames; } } diff --git a/src/main/java/io/github/dsheirer/module/decode/p25/phase2/timeslot/Voice2Timeslot.java b/src/main/java/io/github/dsheirer/module/decode/p25/phase2/timeslot/Voice2Timeslot.java index 35050594..941a1481 100644 --- a/src/main/java/io/github/dsheirer/module/decode/p25/phase2/timeslot/Voice2Timeslot.java +++ b/src/main/java/io/github/dsheirer/module/decode/p25/phase2/timeslot/Voice2Timeslot.java @@ -1,23 +1,20 @@ /* + * ***************************************************************************** + * Copyright (C) 2014-2024 Dennis Sheirer * - * * ****************************************************************************** - * * Copyright (C) 2014-2019 Dennis Sheirer - * * - * * This program is free software: you can redistribute it and/or modify - * * it under the terms of the GNU General Public License as published by - * * the Free Software Foundation, either version 3 of the License, or - * * (at your option) any later version. - * * - * * This program is distributed in the hope that it will be useful, - * * but WITHOUT ANY WARRANTY; without even the implied warranty of - * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * * GNU General Public License for more details. - * * - * * You should have received a copy of the GNU General Public License - * * along with this program. If not, see - * * ***************************************************************************** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + * **************************************************************************** */ package io.github.dsheirer.module.decode.p25.phase2.timeslot; @@ -25,7 +22,6 @@ package io.github.dsheirer.module.decode.p25.phase2.timeslot; import io.github.dsheirer.bits.BinaryMessage; import io.github.dsheirer.bits.CorrectedBinaryMessage; import io.github.dsheirer.module.decode.p25.phase2.enumeration.DataUnitID; - import java.util.ArrayList; import java.util.List; @@ -61,7 +57,7 @@ public class Voice2Timeslot extends AbstractVoiceTimeslot /** * Voice frames contained in this timeslot */ - public List getVoiceFrames() + public synchronized List getVoiceFrames() { if(mVoiceFrames == null) { diff --git a/src/main/java/io/github/dsheirer/module/decode/p25/phase2/timeslot/Voice4Timeslot.java b/src/main/java/io/github/dsheirer/module/decode/p25/phase2/timeslot/Voice4Timeslot.java index bd2f8842..12a4fb8c 100644 --- a/src/main/java/io/github/dsheirer/module/decode/p25/phase2/timeslot/Voice4Timeslot.java +++ b/src/main/java/io/github/dsheirer/module/decode/p25/phase2/timeslot/Voice4Timeslot.java @@ -1,23 +1,20 @@ /* + * ***************************************************************************** + * Copyright (C) 2014-2024 Dennis Sheirer * - * * ****************************************************************************** - * * Copyright (C) 2014-2019 Dennis Sheirer - * * - * * This program is free software: you can redistribute it and/or modify - * * it under the terms of the GNU General Public License as published by - * * the Free Software Foundation, either version 3 of the License, or - * * (at your option) any later version. - * * - * * This program is distributed in the hope that it will be useful, - * * but WITHOUT ANY WARRANTY; without even the implied warranty of - * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * * GNU General Public License for more details. - * * - * * You should have received a copy of the GNU General Public License - * * along with this program. If not, see - * * ***************************************************************************** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + * **************************************************************************** */ package io.github.dsheirer.module.decode.p25.phase2.timeslot; @@ -25,7 +22,6 @@ package io.github.dsheirer.module.decode.p25.phase2.timeslot; import io.github.dsheirer.bits.BinaryMessage; import io.github.dsheirer.bits.CorrectedBinaryMessage; import io.github.dsheirer.module.decode.p25.phase2.enumeration.DataUnitID; - import java.util.ArrayList; import java.util.List; @@ -62,7 +58,7 @@ public class Voice4Timeslot extends AbstractVoiceTimeslot /** * Voice frames contained in this timeslot */ - public List getVoiceFrames() + public synchronized List getVoiceFrames() { if(mVoiceFrames == null) { @@ -71,7 +67,6 @@ public class Voice4Timeslot extends AbstractVoiceTimeslot mVoiceFrames.add(getMessage().getSubMessage(FRAME_2_START, FRAME_2_START + FRAME_LENGTH)); mVoiceFrames.add(getMessage().getSubMessage(FRAME_3_START, FRAME_3_START + FRAME_LENGTH)); mVoiceFrames.add(getMessage().getSubMessage(FRAME_4_START, FRAME_4_START + FRAME_LENGTH)); - return mVoiceFrames; } return mVoiceFrames;