Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer: Create audio stream buffer #2283

Merged
merged 21 commits into from
Jan 22, 2020
Merged

Conversation

ktrzcinx
Copy link
Member

When new component will need to process audio data in two steps,
then temporary circular buffer will be needed. Also extra information
about data stream may be needed to choose right algorithm or assert data
compatibility.

Currently only 'comp_buffer' has such a possibility but it is component
defined in topology - with much wider capabilities - and shouldn't be
created inside component just to hold temporary data stream.

Signed-off-by: Karol Trzcinski [email protected]

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can we not reuse the existing buffer logic ? We should be able to instantiate it directly without IPC, although we may need some new API calls to help with this. I just don't want to see duplication here.

@ktrzcinx
Copy link
Member Author

@lgirdwood I see that in currently we have tendency to duplications, see hb struct in sof/audio/kpb.h and as I far as I know there are similar issue currently under development. So I see need to split comp_buffer to part responsible directly for holding audio samples in circular buffer, base argument for data processing functions and universal brick for nesting when it is such a need.
As you can see I change almost each processing function in code and nowhere were used more fields than are present in this new structure - as usual there are need to only have circular buffer implementation with channel numbers and frame format.

@ktrzcinx ktrzcinx changed the title WIP: buffer: Create audio stream buffer buffer: Create audio stream buffer Jan 15, 2020
Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, it looks like duplication because patch 2 duplicates existing APIs and patch 3 removes the old API. You need to merge the parts of patch 2 into 3 to show that there is no duplication, this makes it easier to follow.

@lgirdwood
Copy link
Member

@ktrzcinx one more question, will there be further updates to kpb to deduplicate code and fully use this update ?

@ktrzcinx
Copy link
Member Author

@lgirdwood do You want to just fully merge patch #2 i #3 ?

Const keyword is added to explicitly indicate that nothing in given
source buffer can be changed in processing functions - read pointers also.

Signed-off-by: Karol Trzcinski <[email protected]>
To keep code clean and consistent create processing function
interface outside comp_data function definition to omit
duplicated definitions.

Signed-off-by: Karol Trzcinski <[email protected]>
Const keyword is added to explicitly indicate that nothing in given
input devices buffer can be changed in processing functions -
- read pointers also.

Signed-off-by: Karol Trzcinski <[email protected]>
Functions like src_get_copy_limits should have const marking to
avoid error related with unintentional fields editing.

Signed-off-by: Karol Trzcinski <[email protected]>
Const keyword is added to explicitly indicate that nothing in given
input devices buffer can be changed in processing functions -
- read pointers also.

Signed-off-by: Karol Trzcinski <[email protected]>
To keep code clean and consistent create processing function
interface outside comp_data function definition to omit
duplicated definitions.

Signed-off-by: Karol Trzcinski <[email protected]>
Const keyword is added to explicitly indicate that nothing in given
input devices buffer can be changed in processing functions -
- read pointers also.

Signed-off-by: Karol Trzcinski <[email protected]>
@ktrzcinx
Copy link
Member Author

Rebase required because of conflicts

To keep code clean and consistent create processing function
interface outside comp_data function definition to omit
duplicated definitions.

Signed-off-by: Karol Trzcinski <[email protected]>
Const keyword is added to explicitly indicate that nothing in given
source buffer can be changed in processing functions - read pointers also.

Signed-off-by: Karol Trzcinski <[email protected]>
This variable is unused in whole project.

Signed-off-by: Karol Trzcinski <[email protected]>
Changed line was longer than 80 chars and refer to nested variable
twice - after changes both problems disappears.

Signed-off-by: Karol Trzcinski <[email protected]>
@lgirdwood
Copy link
Member

@zrombel could you comment on the scan. Thanks.

@zrombel
Copy link

zrombel commented Jan 22, 2020

Xtensa licese server issue. Rerunning build and scan. I've mode some changes to suppress those kind of issues.

When new component will need to process audio data in two steps,
then temporary circular buffer will be needed. Also extra information
about data stream may be needed to choose right algorithm or assert data
compatibility.

Currently only 'comp_buffer' has such a possibility but it is component
defined in topology - with much wider capabilities - and shouldn't be
created inside component just to hold temporary data stream.

Use introduced structure in processing functions, move api responsible
for data processing from buffer to audio_stream module.

Signed-off-by: Karol Trzcinski <[email protected]>
In source code there are places where are implemented pointer
wrapping by hand, what looks quite complicated for a first eye catch
and is messy because of pointer type casting.
Using as_wrap is very well descriptive method and consist with DRY
principle.

as_get_frag has been changed to preprocessor function as it is just
moving given pointer and wrapping result.

Signed-off-by: Karol Trzcinski <[email protected]>
@lgirdwood
Copy link
Member

@xiulipan checkpatch is fine, but showing an error ?

@lgirdwood lgirdwood merged commit e9a9e87 into thesofproject:master Jan 22, 2020
@xiulipan
Copy link
Contributor

@lgirdwood If you scroll down, you will find some warning:

Commit 0b45888e873f ("buffer: Create audio stream buffer")
----------------------------------------------------------
CHECK: Alignment should match open parenthesis
#2669: FILE: src/audio/src/src.c:778:
+		comp_update_buffer_consume(source,
+			consumed * audio_stream_frame_bytes(&source->stream));

CHECK: Alignment should match open parenthesis
#2675: FILE: src/audio/src/src.c:782:
+		comp_update_buffer_produce(sink,
+			produced * audio_stream_frame_bytes(&sink->stream));

CHECK: Macro argument reuse 'buffer' - possible side-effects?
#2959: FILE: src/include/sof/audio/audio_stream.h:43:
+#define audio_stream_read_frag(buffer, idx, size) \
+	audio_stream_get_frag(buffer, buffer->r_ptr, idx, size)

CHECK: Macro argument reuse 'buffer' - possible side-effects?
#2962: FILE: src/include/sof/audio/audio_stream.h:46:
+#define audio_stream_read_frag_s16(buffer, idx) \
+	audio_stream_get_frag(buffer, buffer->r_ptr, idx, sizeof(int16_t))

CHECK: Macro argument reuse 'buffer' - possible side-effects?
#2965: FILE: src/include/sof/audio/audio_stream.h:49:
+#define audio_stream_read_frag_s32(buffer, idx) \
+	audio_stream_get_frag(buffer, buffer->r_ptr, idx, sizeof(int32_t))

CHECK: Macro argument reuse 'buffer' - possible side-effects?
#2968: FILE: src/include/sof/audio/audio_stream.h:52:
+#define audio_stream_write_frag(buffer, idx, size) \
+	audio_stream_get_frag(buffer, buffer->w_ptr, idx, size)

CHECK: Macro argument reuse 'buffer' - possible side-effects?
#2971: FILE: src/include/sof/audio/audio_stream.h:55:
+#define audio_stream_write_frag_s16(buffer, idx) \
+	audio_stream_get_frag(buffer, buffer->w_ptr, idx, sizeof(int16_t))

CHECK: Macro argument reuse 'buffer' - possible side-effects?
#2974: FILE: src/include/sof/audio/audio_stream.h:58:
+#define audio_stream_write_frag_s32(buffer, idx) \
+	audio_stream_get_frag(buffer, buffer->w_ptr, idx, sizeof(int32_t))

CHECK: Alignment should match open parenthesis
#2978: FILE: src/include/sof/audio/audio_stream.h:62:
+static inline void *audio_stream_get_frag(const struct audio_stream *buffer,
+				const void *ptr, uint32_t idx, uint32_t size)

WARNING: Use safe version of memcpy - memcpy_s whenever possible
#4112: FILE: test/cmocka/src/audio/buffer/buffer_wrap.c:36:
+	memcpy(buf->stream.w_ptr, &bytes, 10);

WARNING: Use safe version of memcpy - memcpy_s whenever possible
#4125: FILE: test/cmocka/src/audio/buffer/buffer_wrap.c:45:
+	memcpy(buf->stream.w_ptr, &more_bytes, 5);

WARNING: Use safe version of memcpy - memcpy_s whenever possible
#4163: FILE: test/cmocka/src/audio/buffer/buffer_write.c:37:
+	memcpy(buf->stream.w_ptr, &bytes, 10);

WARNING: Use safe version of memcpy - memcpy_s whenever possible
#4201: FILE: test/cmocka/src/audio/buffer/buffer_write.c:72:
+	memcpy(buf->stream.w_ptr, &bytes, 10);

total: 0 errors, 4 warnings, 9 checks, 4349 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

@ktrzcinx
Copy link
Member Author

@xiulipan @lgirdwood checkpack results is located on github inside iframe with size restrictions:
<p><iframe src="checkpatch.txt" frameborder="0" height="550" width="95%"></iframe></p>

It's quite misleading for me too, maybe it's time to use full available size instead?

@lgirdwood
Copy link
Member

@xiulipan that was not visible yesterday when I checked (and I did double check as I found it odd), it was all good ? Could there be a sync issue ?

@lgirdwood
Copy link
Member

@ktrzcinx can you send a followup PR with the memcpy fixes as per check patch.

@ktrzcinx
Copy link
Member Author

@lgirdwood I didn't introduce memcpy functions in this place, it was before, but yes, I can fix it

@paulstelian97
Copy link
Collaborator

Memcpy functions seem to all be in unit tests? And the actual issue was old but only now discovered due to touching said code?

@ktrzcinx
Copy link
Member Author

@paulstelian97 Right

@xiulipan
Copy link
Contributor

xiulipan commented Feb 3, 2020

@kakulesza @lrgirdwo @plbossart I think it would be some html issue. I wil try to and some fix to make the iframe scroll-able if the checkpatch result is very long.

@ktrzcinx ktrzcinx deleted the cbuf branch March 10, 2020 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants